我需要mapreduce作业的帮助,我的自定义分区器从未被调用。我检查了无数次,但都没有结果。它以前很管用,我不知道为什么现在不行了。任何帮助都会非常感激的。
我正在添加代码(它既不适用于自定义键作为输入,也不适用于非常简单的情况)。
Map器输出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;
}
}
提前多谢了,
亚历克斯
1条答案
按热度按时间pepwfjgg1#
尝试将还原数设置为大于唯一键数的任意数。