Sudarshan kumar
Sudarshan kumar

Reputation: 1585

NullWritable in the context.write() method

How can i put only value in my context.write() method.I don't want to write key in my text file so I don't want to emit Key in my context.write() method.

Here is my mapper code:

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);
    }
}

Reducer code:

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));
    }
}

Upvotes: 0

Views: 4282

Answers (1)

prashant khunt
prashant khunt

Reputation: 154

Try to write NullWritable.get() as Key and specify NullWritable as datatype from mapper to reducer,

i.e
Reducer Definition,

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

Reducer Emission

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

Upvotes: 1

Related Questions