@Override public void initialize(MapReduceTaskContext<byte[], Put> context) throws Exception { InputContext inputContext = context.getInputContext(); Preconditions.checkArgument(PARTITIONED.equals(inputContext.getInputName())); Preconditions.checkArgument(inputContext instanceof PartitionedFileSetInputContext); this.pfsInputcontext = (PartitionedFileSetInputContext) inputContext; Preconditions.checkNotNull(pfsInputcontext.getInputPartitionKey()); Preconditions.checkArgument( pfsInputcontext.getInputPartitionKeys().contains(pfsInputcontext.getInputPartitionKey()) ); Map<String, String> dsArguments = RuntimeArguments.extractScope(Scope.DATASET, PARTITIONED, context.getRuntimeArguments()); PartitionFilter inputPartitionFilter = PartitionedFileSetArguments.getInputPartitionFilter(dsArguments); Preconditions.checkNotNull(inputPartitionFilter); // verify that the partition matches the partition filter for this MapReduce Preconditions.checkArgument(inputPartitionFilter.match(pfsInputcontext.getInputPartitionKey())); }
@Override public void map(LongWritable pos, Text text, Context context) throws IOException, InterruptedException { String line = text.toString(); String[] fields = line.split(SEPARATOR); context.write(rowToWrite, new Put(rowToWrite, Bytes.toBytes(fields[0]), Bytes.toBytes(fields[1]))); context.write(rowToWrite, new Put(rowToWrite, Bytes.toBytes(fields[0] + "_key"), Bytes.toBytes(pfsInputcontext.getInputPartitionKey().toString()))); } }