Search in sources :

Example 6 with RowCell

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));
}
Also used : RowCell(com.google.cloud.bigtable.hbase.adapters.read.RowCell) Result(org.apache.hadoop.hbase.client.Result) Test(org.junit.Test)

Example 7 with RowCell

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());
}
Also used : ImmutableList(com.google.common.collect.ImmutableList) RowCell(com.google.cloud.bigtable.hbase.adapters.read.RowCell) RowCell(com.google.cloud.bigtable.hbase.adapters.read.RowCell) Cell(org.apache.hadoop.hbase.Cell)

Example 8 with RowCell

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();
}
Also used : Query(com.google.cloud.bigtable.data.v2.models.Query) RowCell(com.google.cloud.bigtable.hbase.adapters.read.RowCell) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) ByteString(com.google.protobuf.ByteString) BinaryComparator(org.apache.hadoop.hbase.filter.BinaryComparator) Result(org.apache.hadoop.hbase.client.Result) QualifierFilter(org.apache.hadoop.hbase.filter.QualifierFilter) ResultScanner(org.apache.hadoop.hbase.client.ResultScanner) Scan(org.apache.hadoop.hbase.client.Scan) Cell(org.apache.hadoop.hbase.Cell) RowCell(com.google.cloud.bigtable.hbase.adapters.read.RowCell) Test(org.junit.Test)

Example 9 with RowCell

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();
}
Also used : ResultScanner(org.apache.hadoop.hbase.client.ResultScanner) RowCell(com.google.cloud.bigtable.hbase.adapters.read.RowCell) Result(org.apache.hadoop.hbase.client.Result) Test(org.junit.Test)

Example 10 with RowCell

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();
}
Also used : ResultScanner(org.apache.hadoop.hbase.client.ResultScanner) RowCell(com.google.cloud.bigtable.hbase.adapters.read.RowCell) Result(org.apache.hadoop.hbase.client.Result) Test(org.junit.Test)

Aggregations

RowCell (com.google.cloud.bigtable.hbase.adapters.read.RowCell)16 Result (org.apache.hadoop.hbase.client.Result)15 Test (org.junit.Test)15 ByteString (com.google.protobuf.ByteString)9 Get (org.apache.hadoop.hbase.client.Get)5 ResultScanner (org.apache.hadoop.hbase.client.ResultScanner)5 RowAdapter (com.google.cloud.bigtable.data.v2.models.RowAdapter)4 Cell (org.apache.hadoop.hbase.Cell)3 QualifierFilter (org.apache.hadoop.hbase.filter.QualifierFilter)3 Filters (com.google.cloud.bigtable.data.v2.models.Filters)2 Query (com.google.cloud.bigtable.data.v2.models.Query)2 Scan (org.apache.hadoop.hbase.client.Scan)2 BinaryComparator (org.apache.hadoop.hbase.filter.BinaryComparator)2 WhileMatchFilter (org.apache.hadoop.hbase.filter.WhileMatchFilter)2 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)2 ApiFuture (com.google.api.core.ApiFuture)1 ImmutableList (com.google.common.collect.ImmutableList)1 ArrayList (java.util.ArrayList)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 RetriesExhaustedWithDetailsException (org.apache.hadoop.hbase.client.RetriesExhaustedWithDetailsException)1