use of com.google.cloud.bigtable.hbase.adapters.read.RowCell in project java-bigtable-hbase by googleapis.
the class TestRowResultAdapter method testWithMarkerRow.
@Test
public void testWithMarkerRow() {
Result markerRow = new RowResultAdapter.RowResultBuilder().createScanMarkerRow(ROW_KEY);
assertTrue(underTest.isScanMarkerRow(markerRow));
assertEquals(ROW_KEY, underTest.getKey(markerRow));
Result resultWithOneCell = Result.create(ImmutableList.<Cell>of(new RowCell(ROW_KEY.toByteArray(), COL_FAMILY.getBytes(), QUAL_ONE.toByteArray(), 10L, VALUE.toByteArray())));
assertFalse(underTest.isScanMarkerRow(resultWithOneCell));
}
use of com.google.cloud.bigtable.hbase.adapters.read.RowCell in project java-bigtable-hbase by googleapis.
the class BigtableWhileMatchResultScannerAdapter method externalizeResult.
/**
* Returns {@link Result} if there are matching {@link WhileMatchFilter} labels. If non matching
* labels found it returns {@code null}. This also filters out {@link Cell} with labels.
*
* @param result a {@link Result} object.
* @return a filtered {@link Result} object.
*/
private static Result externalizeResult(Result result) {
int inLabelCount = 0;
int outLabelCount = 0;
ImmutableList.Builder<Cell> filteredCells = ImmutableList.builder();
for (Cell cell : result.rawCells()) {
if (cell instanceof RowCell) {
RowCell rowCell = (RowCell) cell;
for (String label : rowCell.getLabels()) {
// TODO(kevinsi4508): Handle multiple {@link WhileMatchFilter} labels.
if (label.endsWith(WHILE_MATCH_FILTER_IN_LABEL_SUFFIX)) {
inLabelCount++;
} else if (label.endsWith(WHILE_MATCH_FILTER_OUT_LABEL_SUFFIX)) {
outLabelCount++;
}
}
if (rowCell.getLabels().isEmpty()) {
filteredCells.add(rowCell);
}
} else {
// TODO: figure out if this can be removed
filteredCells.add(cell);
}
}
// Checks if there is mismatching {@link WhileMatchFilter} label.
if (inLabelCount != outLabelCount) {
return null;
}
return Result.create(filteredCells.build());
}
use of com.google.cloud.bigtable.hbase.adapters.read.RowCell in project java-bigtable-hbase by googleapis.
the class TestBigtableTable method getScanner_withBigtableResultScannerAdapter.
@Test
public void getScanner_withBigtableResultScannerAdapter() throws IOException {
when(mockBigtableDataClient.readRows(isA(Query.class))).thenReturn(mockResultScanner);
// A row with no matching label. In case of {@link BigtableResultScannerAdapter} the result is
// non-null.
Result expected = Result.create(ImmutableList.<Cell>of(new RowCell(Bytes.toBytes("row_key"), Bytes.toBytes("family_name"), Bytes.toBytes("q_name"), 0, ByteString.EMPTY.toByteArray(), Collections.singletonList("label-in")), new RowCell(Bytes.toBytes("row_key"), Bytes.toBytes("family_name"), Bytes.toBytes("q_name"), 0, Bytes.toBytes("value"))));
when(mockResultScanner.next()).thenReturn(expected);
QualifierFilter filter = new QualifierFilter(CompareOp.EQUAL, new BinaryComparator(Bytes.toBytes("x")));
Scan scan = new Scan();
scan.setFilter(filter);
org.apache.hadoop.hbase.client.ResultScanner resultScanner = table.getScanner(scan);
Result result = resultScanner.next();
assertEquals("row_key", new String(result.getRow()));
List<org.apache.hadoop.hbase.Cell> cells = result.getColumnCells("family_name".getBytes(), "q_name".getBytes());
// HBase ResultScanner now allows cells with labels
assertEquals(2, cells.size());
assertEquals("", new String(CellUtil.cloneValue(cells.get(0))));
assertEquals("value", new String(CellUtil.cloneValue(cells.get(1))));
verify(mockBigtableDataClient).readRows(isA(Query.class));
verify(mockResultScanner).next();
}
use of com.google.cloud.bigtable.hbase.adapters.read.RowCell in project java-bigtable-hbase by googleapis.
the class TestBigtableWhileMatchResultScannerAdapter method adapt_oneRow_hasMatchingLabels.
@Test
public void adapt_oneRow_hasMatchingLabels() throws IOException {
Result expectedResult = Result.create(ImmutableList.<Cell>of(new RowCell(Bytes.toBytes("row"), Bytes.toBytes("family"), Bytes.toBytes("q"), 10000L, Bytes.toBytes("value"), ImmutableList.of("a-in")), new RowCell(Bytes.toBytes("row"), Bytes.toBytes("family"), Bytes.toBytes("q"), 10000L, Bytes.toBytes("value"), ImmutableList.of("a-out"))));
when(mockBigtableResultScanner.next()).thenReturn(expectedResult);
ResultScanner scanner = adapter.adapt(mockBigtableResultScanner, mockSpan);
assertEquals(0, scanner.next().size());
verify(mockBigtableResultScanner).next();
verify(mockSpan, times(0)).end();
}
use of com.google.cloud.bigtable.hbase.adapters.read.RowCell in project java-bigtable-hbase by googleapis.
the class TestBigtableWhileMatchResultScannerAdapter method adapt_oneRow.
@Test
public void adapt_oneRow() throws IOException {
Result expectedResult = Result.create(ImmutableList.<Cell>of(new RowCell(Bytes.toBytes("row"), Bytes.toBytes("family"), Bytes.toBytes("q"), 10000L, Bytes.toBytes("value"), ImmutableList.<String>of())));
when(mockBigtableResultScanner.next()).thenReturn(expectedResult);
ResultScanner scanner = adapter.adapt(mockBigtableResultScanner, mockSpan);
assertArrayEquals(expectedResult.rawCells(), scanner.next().rawCells());
verify(mockBigtableResultScanner).next();
verify(mockSpan, times(0)).end();
}
Aggregations