Reporter reporter = mock(Reporter.class); final byte[] bSeparator = Bytes.toBytes(" "); gTableMap = new GroupingTableMap(); Configuration cfg = new Configuration(); cfg.set(GroupingTableMap.GROUP_COLUMNS, "familyA:qualifierA familyB:qualifierB"); JobConf jobConf = new JobConf(cfg); gTableMap.configure(jobConf); gTableMap.map(null, result, outputCollector, reporter); verify(result).listCells(); Assert.assertTrue("Output not received", outputCollected.get()); final byte[] secondPartValue = Bytes.toBytes("4678456942345"); byte[][] data = { firstPartValue, secondPartValue }; ImmutableBytesWritable byteWritable = gTableMap.createGroupKey(data); assertArrayEquals(org.apache.hbase.thirdparty.com.google.common.primitives. Bytes.concat(firstPartValue, } finally { if (gTableMap != null) gTableMap.close();
/** * 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 * @param value * @param output * @param reporter * @throws IOException */ public void map(ImmutableBytesWritable key, Result value, OutputCollector<ImmutableBytesWritable,Result> output, Reporter reporter) throws IOException { byte[][] keyVals = extractKeyValues(value); if(keyVals != null) { ImmutableBytesWritable tKey = createGroupKey(keyVals); output.collect(tKey, value); } }
@Test @SuppressWarnings({ "deprecation" }) public void shouldReturnNullFromCreateGroupKey() throws Exception { GroupingTableMap gTableMap = null; try { gTableMap = new GroupingTableMap(); assertNull(gTableMap.createGroupKey(null)); } finally { if(gTableMap != null) gTableMap.close(); } } }
@Test @SuppressWarnings({ "deprecation", "unchecked" }) public void shouldNotCallCollectonSinceFindUniqueKeyValueMoreThanOnes() throws Exception { GroupingTableMap gTableMap = null; try { Result result = mock(Result.class); Reporter reporter = mock(Reporter.class); gTableMap = new GroupingTableMap(); Configuration cfg = new Configuration(); cfg.set(GroupingTableMap.GROUP_COLUMNS, "familyA:qualifierA familyB:qualifierB"); JobConf jobConf = new JobConf(cfg); gTableMap.configure(jobConf); byte[] row = {}; List<Cell> keyValues = ImmutableList.<Cell>of( new KeyValue(row, "familyA".getBytes(), "qualifierA".getBytes(), Bytes.toBytes("1111")), new KeyValue(row, "familyA".getBytes(), "qualifierA".getBytes(), Bytes.toBytes("2222")), new KeyValue(row, "familyB".getBytes(), "qualifierB".getBytes(), Bytes.toBytes("3333"))); when(result.listCells()).thenReturn(keyValues); OutputCollector<ImmutableBytesWritable, Result> outputCollectorMock = mock(OutputCollector.class); gTableMap.map(null, result, outputCollectorMock, reporter); verify(result).listCells(); verifyZeroInteractions(outputCollectorMock); } finally { if (gTableMap != null) gTableMap.close(); } }
@Test @SuppressWarnings({ "deprecation" }) public void shouldReturnNullFromCreateGroupKey() throws Exception { GroupingTableMap gTableMap = null; try { gTableMap = new GroupingTableMap(); assertNull(gTableMap.createGroupKey(null)); } finally { if(gTableMap != null) gTableMap.close(); } } }
@Test @SuppressWarnings({ "deprecation", "unchecked" }) public void shouldCreateNewKeyAlthoughExtraKey() throws Exception { GroupingTableMap gTableMap = null; try { Result result = mock(Result.class); Reporter reporter = mock(Reporter.class); gTableMap = new GroupingTableMap(); Configuration cfg = new Configuration(); cfg.set(GroupingTableMap.GROUP_COLUMNS, "familyA:qualifierA familyB:qualifierB"); JobConf jobConf = new JobConf(cfg); gTableMap.configure(jobConf); byte[] row = {}; List<Cell> keyValues = ImmutableList.<Cell>of( new KeyValue(row, "familyA".getBytes(), "qualifierA".getBytes(), Bytes.toBytes("1111")), new KeyValue(row, "familyB".getBytes(), "qualifierB".getBytes(), Bytes.toBytes("2222")), new KeyValue(row, "familyC".getBytes(), "qualifierC".getBytes(), Bytes.toBytes("3333"))); when(result.listCells()).thenReturn(keyValues); OutputCollector<ImmutableBytesWritable, Result> outputCollectorMock = mock(OutputCollector.class); gTableMap.map(null, result, outputCollectorMock, reporter); verify(result).listCells(); verify(outputCollectorMock, times(1)) .collect(any(), any()); verifyNoMoreInteractions(outputCollectorMock); } finally { if (gTableMap != null) gTableMap.close(); } }
/** * 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 * @param value * @param output * @param reporter * @throws IOException */ public void map(ImmutableBytesWritable key, Result value, OutputCollector<ImmutableBytesWritable,Result> output, Reporter reporter) throws IOException { byte[][] keyVals = extractKeyValues(value); if(keyVals != null) { ImmutableBytesWritable tKey = createGroupKey(keyVals); output.collect(tKey, value); } }
@Test @SuppressWarnings({ "deprecation" }) public void shouldReturnNullFromCreateGroupKey() throws Exception { GroupingTableMap gTableMap = null; try { gTableMap = new GroupingTableMap(); assertNull(gTableMap.createGroupKey(null)); } finally { if(gTableMap != null) gTableMap.close(); } } }
/** * 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 * @param value * @param output * @param reporter * @throws IOException */ public void map(ImmutableBytesWritable key, Result value, OutputCollector<ImmutableBytesWritable,Result> output, Reporter reporter) throws IOException { byte[][] keyVals = extractKeyValues(value); if(keyVals != null) { ImmutableBytesWritable tKey = createGroupKey(keyVals); output.collect(tKey, value); } }
@Test @SuppressWarnings({ "deprecation", "unchecked" }) public void shouldNotCallCollectonSinceFindUniqueKeyValueMoreThanOnes() throws Exception { GroupingTableMap gTableMap = null; try { Result result = mock(Result.class); Reporter reporter = mock(Reporter.class); gTableMap = new GroupingTableMap(); Configuration cfg = new Configuration(); cfg.set(GroupingTableMap.GROUP_COLUMNS, "familyA:qualifierA familyB:qualifierB"); JobConf jobConf = new JobConf(cfg); gTableMap.configure(jobConf); byte[] row = {}; List<Cell> keyValues = ImmutableList.<Cell>of( new KeyValue(row, "familyA".getBytes(), "qualifierA".getBytes(), Bytes.toBytes("1111")), new KeyValue(row, "familyA".getBytes(), "qualifierA".getBytes(), Bytes.toBytes("2222")), new KeyValue(row, "familyB".getBytes(), "qualifierB".getBytes(), Bytes.toBytes("3333"))); when(result.listCells()).thenReturn(keyValues); OutputCollector<ImmutableBytesWritable, Result> outputCollectorMock = mock(OutputCollector.class); gTableMap.map(null, result, outputCollectorMock, reporter); verify(result).listCells(); verifyZeroInteractions(outputCollectorMock); } finally { if (gTableMap != null) gTableMap.close(); } }
/** * 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 * @param value * @param output * @param reporter * @throws IOException */ public void map(ImmutableBytesWritable key, Result value, OutputCollector<ImmutableBytesWritable,Result> output, Reporter reporter) throws IOException { byte[][] keyVals = extractKeyValues(value); if(keyVals != null) { ImmutableBytesWritable tKey = createGroupKey(keyVals); output.collect(tKey, value); } }
@Test @SuppressWarnings({ "deprecation", "unchecked" }) public void shouldCreateNewKeyAlthoughExtraKey() throws Exception { GroupingTableMap gTableMap = null; try { Result result = mock(Result.class); Reporter reporter = mock(Reporter.class); gTableMap = new GroupingTableMap(); Configuration cfg = new Configuration(); cfg.set(GroupingTableMap.GROUP_COLUMNS, "familyA:qualifierA familyB:qualifierB"); JobConf jobConf = new JobConf(cfg); gTableMap.configure(jobConf); byte[] row = {}; List<Cell> keyValues = ImmutableList.<Cell>of( new KeyValue(row, "familyA".getBytes(), "qualifierA".getBytes(), Bytes.toBytes("1111")), new KeyValue(row, "familyB".getBytes(), "qualifierB".getBytes(), Bytes.toBytes("2222")), new KeyValue(row, "familyC".getBytes(), "qualifierC".getBytes(), Bytes.toBytes("3333"))); when(result.listCells()).thenReturn(keyValues); OutputCollector<ImmutableBytesWritable, Result> outputCollectorMock = mock(OutputCollector.class); gTableMap.map(null, result, outputCollectorMock, reporter); verify(result).listCells(); verify(outputCollectorMock, times(1)) .collect(any(), any()); verifyNoMoreInteractions(outputCollectorMock); } finally { if (gTableMap != null) gTableMap.close(); } }
/** * 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 * @param value * @param output * @param reporter * @throws IOException */ public void map(ImmutableBytesWritable key, Result value, OutputCollector<ImmutableBytesWritable,Result> output, Reporter reporter) throws IOException { byte[][] keyVals = extractKeyValues(value); if(keyVals != null) { ImmutableBytesWritable tKey = createGroupKey(keyVals); output.collect(tKey, value); } }
@Test @SuppressWarnings({ "deprecation", "unchecked" }) public void shouldNotCallCollectonSinceFindUniqueKeyValueMoreThanOnes() throws Exception { GroupingTableMap gTableMap = null; try { Result result = mock(Result.class); Reporter reporter = mock(Reporter.class); gTableMap = new GroupingTableMap(); Configuration cfg = new Configuration(); cfg.set(GroupingTableMap.GROUP_COLUMNS, "familyA:qualifierA familyB:qualifierB"); JobConf jobConf = new JobConf(cfg); gTableMap.configure(jobConf); byte[] row = {}; List<Cell> keyValues = ImmutableList.<Cell>of( new KeyValue(row, "familyA".getBytes(), "qualifierA".getBytes(), Bytes.toBytes("1111")), new KeyValue(row, "familyA".getBytes(), "qualifierA".getBytes(), Bytes.toBytes("2222")), new KeyValue(row, "familyB".getBytes(), "qualifierB".getBytes(), Bytes.toBytes("3333"))); when(result.listCells()).thenReturn(keyValues); OutputCollector<ImmutableBytesWritable, Result> outputCollectorMock = mock(OutputCollector.class); gTableMap.map(null, result, outputCollectorMock, reporter); verify(result).listCells(); verifyZeroInteractions(outputCollectorMock); } finally { if (gTableMap != null) gTableMap.close(); } }
@Test @SuppressWarnings({ "deprecation", "unchecked" }) public void shouldCreateNewKeyAlthoughExtraKey() throws Exception { GroupingTableMap gTableMap = null; try { Result result = mock(Result.class); Reporter reporter = mock(Reporter.class); gTableMap = new GroupingTableMap(); Configuration cfg = new Configuration(); cfg.set(GroupingTableMap.GROUP_COLUMNS, "familyA:qualifierA familyB:qualifierB"); JobConf jobConf = new JobConf(cfg); gTableMap.configure(jobConf); byte[] row = {}; List<Cell> keyValues = ImmutableList.<Cell>of( new KeyValue(row, "familyA".getBytes(), "qualifierA".getBytes(), Bytes.toBytes("1111")), new KeyValue(row, "familyB".getBytes(), "qualifierB".getBytes(), Bytes.toBytes("2222")), new KeyValue(row, "familyC".getBytes(), "qualifierC".getBytes(), Bytes.toBytes("3333"))); when(result.listCells()).thenReturn(keyValues); OutputCollector<ImmutableBytesWritable, Result> outputCollectorMock = mock(OutputCollector.class); gTableMap.map(null, result, outputCollectorMock, reporter); verify(result).listCells(); verify(outputCollectorMock, times(1)) .collect(any(), any()); verifyNoMoreInteractions(outputCollectorMock); } finally { if (gTableMap != null) gTableMap.close(); } }
Reporter reporter = mock(Reporter.class); final byte[] bSeparator = Bytes.toBytes(" "); gTableMap = new GroupingTableMap(); Configuration cfg = new Configuration(); cfg.set(GroupingTableMap.GROUP_COLUMNS, "familyA:qualifierA familyB:qualifierB"); JobConf jobConf = new JobConf(cfg); gTableMap.configure(jobConf); gTableMap.map(null, result, outputCollector, reporter); verify(result).listCells(); Assert.assertTrue("Output not received", outputCollected.get()); final byte[] secondPartValue = Bytes.toBytes("4678456942345"); byte[][] data = { firstPartValue, secondPartValue }; ImmutableBytesWritable byteWritable = gTableMap.createGroupKey(data); assertArrayEquals(org.apache.hbase.thirdparty.com.google.common.primitives. Bytes.concat(firstPartValue, } finally { if (gTableMap != null) gTableMap.close();
Reporter reporter = mock(Reporter.class); final byte[] bSeparator = Bytes.toBytes(" "); gTableMap = new GroupingTableMap(); Configuration cfg = new Configuration(); cfg.set(GroupingTableMap.GROUP_COLUMNS, "familyA:qualifierA familyB:qualifierB"); JobConf jobConf = new JobConf(cfg); gTableMap.configure(jobConf); gTableMap.map(null, result, outputCollector, reporter); verify(result).listCells(); Assert.assertTrue("Output not received", outputCollected.get()); final byte[] secondPartValue = Bytes.toBytes("4678456942345"); byte[][] data = { firstPartValue, secondPartValue }; ImmutableBytesWritable byteWritable = gTableMap.createGroupKey(data); assertArrayEquals(org.apache.hbase.thirdparty.com.google.common.primitives. Bytes.concat(firstPartValue, } finally { if (gTableMap != null) gTableMap.close();