0


我需要有关 mapreduce 工作的帮助,我的自定义分区器从未被调用。我检查了所有内容数百万次,但没有结果。前一阵子还可以用,不知道为什么现在不行了。任何帮助都会非常感激。
我正在添加代码(对于非常简单的情况,它也不适用于自定义键作为输入)。
Mapper 输出正确的值 100%,然后跳过 partitioner。

//import of libs
import org.apache.hadoop.conf.Configured;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.Reducer;
import org.apache.hadoop.mapreduce.Partitioner;
import org.apache.hadoop.hbase.mapreduce.TableMapper;
import org.apache.hadoop.hbase.mapreduce.TableMapReduceUtil;
...

public class hbaseCountTest extends Configured implements Tool {
....

static class myMapper extends TableMapper<Text,Text> {
    @Override
    public void map(ImmutableBytesWritable rowKey,Result result, Context context) throws IOException {
        ...... //dropping some calculations
        context.write(new Text(gender), new Text(capsStr)); // everything is right here, checked.
    }

}

    public static class myPartitioner extends Partitioner<Text, Text> {
    @Override
    public int getPartition(Text key, Text value, int NumReduceTasks) {
//getPartitioner IS NEVER INVOKED
        System.out.println("partitioner started"); 
        String heur = value.toString().split(":")[0]; 
        int h = Integer.parseInt(heur);
        if (h<10) {
            ... return... //dropping some calculations
        } else if (h>9 && h<19) {
            ...
        } else 
            {
            ...
            }
    }

}

@Override
public int run(String[] arg0) throws Exception {
    Job job = Job.getInstance(getConf(), "jobName1");
    job.setNumReduceTasks(3);
    job.setJarByClass(getClass());
    Configuration conf = job.getConfiguration();
    HBaseConfiguration.merge(conf, HBaseConfiguration.create(conf));
    conf.addResource("/home/hadoop/Training/CDH4/hadoop-2.0.0-cdh4.0.0/conf/hadoop-local.xml");
    conf.addResource("/home/hadoop/Training/CDH4/hadoop-2.0.0-cdh4.0.0/conf/mapred-site.xml");
    FileSystem fs = FileSystem.get(getConf());
    if (fs.exists(new Path(arg0[0]))) {
        fs.delete(new Path(arg0[0]));
    }
    Scan scan = new Scan();
    scan.addColumn(toBytes(famName), toBytes(colNamePage));
    scan.addColumn(toBytes(famName), toBytes(colNameTime));
    scan.addColumn(toBytes(famName1), toBytes(colNameRegion));
    scan.addColumn(toBytes(famName1), toBytes(colNameGender));
    TableMapReduceUtil.initTableMapperJob(tableName, scan, myMapper.class, Text.class, Text.class, job);

    job.setPartitionerClass(myPartitioner.class);
    job.setReducerClass(myReducer.class);
    job.setOutputFormatClass(TextOutputFormat.class);
    TextOutputFormat.setOutputPath(job, new Path(arg0[0]));
    job.setOutputKeyClass(TextOutputFormat.class);
    job.setOutputValueClass(TextOutputFormat.class);
            job.setNumReduceTasks(3);
    return job.waitForCompletion(true)?0:1;
}

}

非常感谢,
亚历克斯

4

1 回答 1

0

尝试将 reducer 的数量设置为大于唯一键数量的任何数字。

于 2015-03-18T23:53:08.150 回答