You are viewing a plain text version of this content. The canonical link for it is here.
Posted to common-user@hadoop.apache.org by Konstantin Zhukov <kz...@thumbtack.net> on 2015/10/27 10:31:38 UTC

Keys in TableReducer is empty when map reads from the HDFS

Could you please give me advise how I can resolve my problem?

Now I read file from the hdfs and it is ok. I log values before write it in context and it is right. But if I use TableReducer I get empty keys.

public class WordNetJob {
    private static final Logger log = Logger.getLogger(WordNetJob.class);

    public static void main(String[] args) throws Exception {
        Configuration conf = HBaseConfiguration.create();
        conf.set("hbase.zookeeper.quorum", "localhost");

        Job job = Job.getInstance(conf, "WordNet");

        job.setJarByClass(WordNetJob.class);

        job.setMapOutputKeyClass(Text.class);
        job.setMapOutputValueClass(Text.class);
        job.setMapperClass(WordNetMapper.class);

        TableMapReduceUtil.initTableReducerJob("Neighbors", WordNetReducer.class, job);
        job.setReducerClass(WordNetReducer.class);

        FileInputFormat.setInputPaths(job, new Path("input"));
        job.waitForCompletion(true);
    }

    public static class WordNetMapper extends Mapper<LongWritable, Text, Text, Text> {
        private static final Logger log = Logger.getLogger(WordNetMapper.class);

        @Override
        protected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {
            //...
            log.info <http://log.info/>("Key: [" + new Text(currentWord).toString() + "]; Value: [" + new Text(previousWord).toString() + "]"); //it is good
            context.write(new Text(previousWord), new Text(currentWord));
        }
    }

    public static class WordNetReducer extends TableReducer<Text, Text, ImmutableBytesWritable> {
        private static final Logger log = Logger.getLogger(WordNetReducer.class);

        @Override
        protected void reduce(Text key, Iterable<Text> values, Context context) throws IOException,
                InterruptedException {
            //..
            log.info <http://log.info/>("ReduceKey: " + key.toString()); //key is empty now
            //..
        }
    }
}