/** * Extract the grouping columns from value to construct a new key. Pass the * new key and value to reduce. If any of the grouping columns are not found * in the value, the record is skipped. * * @param key The current key. * @param value The current value. * @param context The current context. * @throws IOException When writing the record fails. * @throws InterruptedException When the job is aborted. */ @Override public void map(ImmutableBytesWritable key, Result value, Context context) throws IOException, InterruptedException { byte[][] keyVals = extractKeyValues(value); if(keyVals != null) { ImmutableBytesWritable tKey = createGroupKey(keyVals); context.write(tKey, value); } }
/** * Test GroupingTableMapper class */ @Test public void testGroupingTableMapper() throws Exception { GroupingTableMapper mapper = new GroupingTableMapper(); Configuration configuration = new Configuration(); configuration.set(GroupingTableMapper.GROUP_COLUMNS, "family1:clm family2:clm"); mapper.setConf(configuration); Result result = mock(Result.class); @SuppressWarnings("unchecked") Mapper<ImmutableBytesWritable, Result, ImmutableBytesWritable, Result>.Context context = mock(Mapper.Context.class); context.write(any(), any()); List<Cell> keyValue = new ArrayList<>(); byte[] row = {}; keyValue.add(new KeyValue(row, Bytes.toBytes("family2"), Bytes.toBytes("clm"), Bytes .toBytes("value1"))); keyValue.add(new KeyValue(row, Bytes.toBytes("family1"), Bytes.toBytes("clm"), Bytes .toBytes("value2"))); when(result.listCells()).thenReturn(keyValue); mapper.map(null, result, context); // template data byte[][] data = { Bytes.toBytes("value1"), Bytes.toBytes("value2") }; ImmutableBytesWritable ibw = mapper.createGroupKey(data); verify(context).write(ibw, result); }
/** * Extract the grouping columns from value to construct a new key. Pass the * new key and value to reduce. If any of the grouping columns are not found * in the value, the record is skipped. * * @param key The current key. * @param value The current value. * @param context The current context. * @throws IOException When writing the record fails. * @throws InterruptedException When the job is aborted. */ @Override public void map(ImmutableBytesWritable key, Result value, Context context) throws IOException, InterruptedException { byte[][] keyVals = extractKeyValues(value); if(keyVals != null) { ImmutableBytesWritable tKey = createGroupKey(keyVals); context.write(tKey, value); } }
/** * Extract the grouping columns from value to construct a new key. Pass the * new key and value to reduce. If any of the grouping columns are not found * in the value, the record is skipped. * * @param key The current key. * @param value The current value. * @param context The current context. * @throws IOException When writing the record fails. * @throws InterruptedException When the job is aborted. */ @Override public void map(ImmutableBytesWritable key, Result value, Context context) throws IOException, InterruptedException { byte[][] keyVals = extractKeyValues(value); if(keyVals != null) { ImmutableBytesWritable tKey = createGroupKey(keyVals); context.write(tKey, value); } }
/** * Extract the grouping columns from value to construct a new key. Pass the * new key and value to reduce. If any of the grouping columns are not found * in the value, the record is skipped. * * @param key The current key. * @param value The current value. * @param context The current context. * @throws IOException When writing the record fails. * @throws InterruptedException When the job is aborted. */ @Override public void map(ImmutableBytesWritable key, Result value, Context context) throws IOException, InterruptedException { byte[][] keyVals = extractKeyValues(value); if(keyVals != null) { ImmutableBytesWritable tKey = createGroupKey(keyVals); context.write(tKey, value); } }
/** * Extract the grouping columns from value to construct a new key. Pass the * new key and value to reduce. If any of the grouping columns are not found * in the value, the record is skipped. * * @param key The current key. * @param value The current value. * @param context The current context. * @throws IOException When writing the record fails. * @throws InterruptedException When the job is aborted. */ @Override public void map(ImmutableBytesWritable key, Result value, Context context) throws IOException, InterruptedException { byte[][] keyVals = extractKeyValues(value); if(keyVals != null) { ImmutableBytesWritable tKey = createGroupKey(keyVals); context.write(tKey, value); } }
/** * Test GroupingTableMapper class */ @Test public void testGroupingTableMapper() throws Exception { GroupingTableMapper mapper = new GroupingTableMapper(); Configuration configuration = new Configuration(); configuration.set(GroupingTableMapper.GROUP_COLUMNS, "family1:clm family2:clm"); mapper.setConf(configuration); Result result = mock(Result.class); @SuppressWarnings("unchecked") Mapper<ImmutableBytesWritable, Result, ImmutableBytesWritable, Result>.Context context = mock(Mapper.Context.class); context.write(any(), any()); List<Cell> keyValue = new ArrayList<>(); byte[] row = {}; keyValue.add(new KeyValue(row, Bytes.toBytes("family2"), Bytes.toBytes("clm"), Bytes .toBytes("value1"))); keyValue.add(new KeyValue(row, Bytes.toBytes("family1"), Bytes.toBytes("clm"), Bytes .toBytes("value2"))); when(result.listCells()).thenReturn(keyValue); mapper.map(null, result, context); // template data byte[][] data = { Bytes.toBytes("value1"), Bytes.toBytes("value2") }; ImmutableBytesWritable ibw = mapper.createGroupKey(data); verify(context).write(ibw, result); }
/** * Test GroupingTableMapper class */ @Test public void testGroupingTableMapper() throws Exception { GroupingTableMapper mapper = new GroupingTableMapper(); Configuration configuration = new Configuration(); configuration.set(GroupingTableMapper.GROUP_COLUMNS, "family1:clm family2:clm"); mapper.setConf(configuration); Result result = mock(Result.class); @SuppressWarnings("unchecked") Mapper<ImmutableBytesWritable, Result, ImmutableBytesWritable, Result>.Context context = mock(Mapper.Context.class); context.write(any(), any()); List<Cell> keyValue = new ArrayList<>(); byte[] row = {}; keyValue.add(new KeyValue(row, Bytes.toBytes("family2"), Bytes.toBytes("clm"), Bytes .toBytes("value1"))); keyValue.add(new KeyValue(row, Bytes.toBytes("family1"), Bytes.toBytes("clm"), Bytes .toBytes("value2"))); when(result.listCells()).thenReturn(keyValue); mapper.map(null, result, context); // template data byte[][] data = { Bytes.toBytes("value1"), Bytes.toBytes("value2") }; ImmutableBytesWritable ibw = mapper.createGroupKey(data); verify(context).write(ibw, result); }