context.write()方法中的NullWritable

时间:2016-12-22 03:06:54

标签: hadoop mapreduce

我怎么能只在我的context.write()方法中放入值。我不想在我的文本文件中写密钥所以我不想在我的context.write()中发出Key方法

这是我的映射器代码:

public class MyMapper extends TableMapper<Text, IntWritable> {
    private final IntWritable ONE = new IntWritable(1);
    private Text text = new Text();
    public void map(ImmutableBytesWritable row, Result value, Context context)
        throws IOException, InterruptedException {
String FundamentalSeriesId = new String(value.getValue(Bytes.toBytes("cf"), Bytes.toBytes("FundamentalSeriesId")));
text.set(FundamentalSeriesId+"|^|"+FundamentalSeriesId_objectTypeId+"|^|"+FundamentalSeriesId_objectType+"|^|"+financialPeriodEndDate+"|^|"+financialPeriodType+"|^|"+LineItemId+"|^|"+analyticItemInstanceKey+"|^|"+AnalyticValue+"|^|"+AnalyticConceptCode+"|^|"+AnalyticValue_currencyId+"|^|"+AnalyticIsEstimated+"|^|"+AnalyticAuditabilityEquation+"|^|"+FinancialPeriodTypeId+""+AnalyticConceptId+"|^|"+AnalyticLineItem_isYearToDate+"|^|"+IsAnnual+"|^|"+FFAction+"|!|"); 

    context.write(text, ONE);
    }
}

减速机代码:

public class MyReducer extends Reducer<Text, IntWritable, Text, IntWritable> {

    public void reduce(Text key, Iterable<IntWritable> values, Context context)
        throws IOException, InterruptedException {
    int i = 0;
    for (IntWritable val : values) {
        i += val.get();
    }
    context.write(key, new IntWritable(i));
    }
}

1 个答案:

答案 0 :(得分:1)

尝试将NullWritable.get()写为Key,并将NullWritable指定为从mapper到reducer的数据类型,


减速机定义,

MyReducer extends Reducer<Text, IntWritable, NullWritable, IntWritable>

减速器排放

context.write(NullWritable.get(), value);