我需要mapreduce作业的帮助,我的自定义分区器永远不会被调用。我检查了一百万次,但没有结果。它曾经工作了一段时间,我不知道为什么现在它不是。
任何帮助都会非常有用
我正在添加代码(对于非常简单的情况,它不能用于自定义键作为输入)。
Mapper输出100%的正确值,然后跳过分区器。
//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;
}
}
提前多多谢谢,
亚历
答案 0 :(得分:0)
尝试将减速器数量设置为大于唯一键数量的任何数量。