Search in sources :

Example 26 with RowCell

use of com.google.cloud.bigtable.data.v2.models.RowCell in project java-bigtable-hbase by googleapis.

the class TestRowResultAdapter method testReset.

@Test
public void testReset() {
    RowAdapter.RowBuilder<Result> rowBuilder = underTest.createRowBuilder();
    rowBuilder.startRow(ROW_KEY);
    rowBuilder.startCell(COL_FAMILY, QUAL_ONE, 10000L, Collections.<String>emptyList(), VALUE.size());
    rowBuilder.cellValue(VALUE);
    rowBuilder.finishCell();
    rowBuilder.reset();
    ByteString anotherKey = ByteString.copyFromUtf8("another-rowKey");
    rowBuilder.startRow(anotherKey);
    rowBuilder.startCell(COL_FAMILY, QUAL_TWO, 40000L, LABELS, VALUE.size());
    rowBuilder.cellValue(VALUE);
    rowBuilder.finishCell();
    Result actual = rowBuilder.finishRow();
    assertResult(Result.create(ImmutableList.<Cell>of(new RowCell(anotherKey.toByteArray(), COL_FAMILY.getBytes(), QUAL_TWO.toByteArray(), 40L, VALUE.toByteArray()))), actual);
}
Also used : RowAdapter(com.google.cloud.bigtable.data.v2.models.RowAdapter) ByteString(com.google.protobuf.ByteString) RowCell(com.google.cloud.bigtable.hbase.adapters.read.RowCell) RowCell(com.google.cloud.bigtable.hbase.adapters.read.RowCell) Cell(org.apache.hadoop.hbase.Cell) Result(org.apache.hadoop.hbase.client.Result) Test(org.junit.Test)

Example 27 with RowCell

use of com.google.cloud.bigtable.data.v2.models.RowCell in project java-bigtable by googleapis.

the class Filters method printRow.

private static void printRow(Row row) {
    System.out.printf("Reading data for %s%n", row.getKey().toStringUtf8());
    String colFamily = "";
    for (RowCell cell : row.getCells()) {
        if (!cell.getFamily().equals(colFamily)) {
            colFamily = cell.getFamily();
            System.out.printf("Column Family %s%n", colFamily);
        }
        String labels = cell.getLabels().size() == 0 ? "" : " [" + String.join(",", cell.getLabels()) + "]";
        System.out.printf("\t%s: %s @%s%s%n", cell.getQualifier().toStringUtf8(), cell.getValue().toStringUtf8(), cell.getTimestamp(), labels);
    }
    System.out.println();
}
Also used : RowCell(com.google.cloud.bigtable.data.v2.models.RowCell)

Example 28 with RowCell

use of com.google.cloud.bigtable.data.v2.models.RowCell in project java-bigtable by googleapis.

the class NativeImageBigtableSample method readData.

static void readData(BigtableDataClient client, String tableId) {
    Query query = Query.create(tableId).prefix("");
    ServerStream<Row> rows = client.readRows(query);
    System.out.println("Reading phone data in table:");
    for (Row row : rows) {
        System.out.println("Key: " + row.getKey().toStringUtf8());
        for (RowCell cell : row.getCells()) {
            System.out.printf("\t%s: %s @%s\n", cell.getQualifier().toStringUtf8(), cell.getValue().toStringUtf8(), cell.getTimestamp());
        }
        System.out.println();
    }
}
Also used : Query(com.google.cloud.bigtable.data.v2.models.Query) RowCell(com.google.cloud.bigtable.data.v2.models.RowCell) Row(com.google.cloud.bigtable.data.v2.models.Row)

Example 29 with RowCell

use of com.google.cloud.bigtable.data.v2.models.RowCell in project java-bigtable by googleapis.

the class BigtableDataClientTest method existsTest.

@Test
public void existsTest() {
    Mockito.when(mockStub.readRowCallable()).thenReturn(mockReadRowCallable);
    Query expectedQuery = Query.create("fake-table").rowKey("fake-row-key").filter(FILTERS.chain().filter(FILTERS.limit().cellsPerRow(1)).filter(FILTERS.value().strip()));
    Row row = Row.create(ByteString.copyFromUtf8("fake-row-key"), ImmutableList.<RowCell>of());
    Mockito.when(mockReadRowCallable.futureCall(expectedQuery)).thenReturn(ApiFutures.immediateFuture(row)).thenReturn(ApiFutures.<Row>immediateFuture(null));
    boolean result = bigtableDataClient.exists("fake-table", "fake-row-key");
    boolean anotherResult = bigtableDataClient.exists("fake-table", ByteString.copyFromUtf8("fake-row-key"));
    assertThat(result).isTrue();
    assertThat(anotherResult).isFalse();
    Mockito.verify(mockReadRowCallable, Mockito.times(2)).futureCall(expectedQuery);
}
Also used : Query(com.google.cloud.bigtable.data.v2.models.Query) Row(com.google.cloud.bigtable.data.v2.models.Row) ReadModifyWriteRow(com.google.cloud.bigtable.data.v2.models.ReadModifyWriteRow) Test(org.junit.Test)

Example 30 with RowCell

use of com.google.cloud.bigtable.data.v2.models.RowCell in project java-bigtable by googleapis.

the class HelloWorld method readSingleRow.

/**
 * Demonstrates how to read a single row from a table.
 */
public Row readSingleRow() {
    // [START bigtable_hw_get_by_key]
    try {
        System.out.println("\nReading a single row by row key");
        Row row = dataClient.readRow(tableId, ROW_KEY_PREFIX + 0);
        System.out.println("Row: " + row.getKey().toStringUtf8());
        for (RowCell cell : row.getCells()) {
            System.out.printf("Family: %s    Qualifier: %s    Value: %s%n", cell.getFamily(), cell.getQualifier().toStringUtf8(), cell.getValue().toStringUtf8());
        }
        return row;
    } catch (NotFoundException e) {
        System.err.println("Failed to read from a non-existent table: " + e.getMessage());
        return null;
    }
// [END bigtable_hw_get_by_key]
}
Also used : RowCell(com.google.cloud.bigtable.data.v2.models.RowCell) NotFoundException(com.google.api.gax.rpc.NotFoundException) Row(com.google.cloud.bigtable.data.v2.models.Row)

Aggregations

Test (org.junit.Test)22 Row (com.google.cloud.bigtable.data.v2.models.Row)21 RowCell (com.google.cloud.bigtable.data.v2.models.RowCell)16 Query (com.google.cloud.bigtable.data.v2.models.Query)10 ByteString (com.google.protobuf.ByteString)10 Result (org.apache.hadoop.hbase.client.Result)10 ReadModifyWriteRow (com.google.cloud.bigtable.data.v2.models.ReadModifyWriteRow)9 RowCell (com.google.cloud.bigtable.hbase.adapters.read.RowCell)8 NotFoundException (com.google.api.gax.rpc.NotFoundException)4 RowAdapter (com.google.cloud.bigtable.data.v2.models.RowAdapter)4 QualifierFilter (org.apache.hadoop.hbase.filter.QualifierFilter)3 ReadRowsRequest (com.google.bigtable.v2.ReadRowsRequest)2 ReadRowsResponse (com.google.bigtable.v2.ReadRowsResponse)2 BigtableDataClient (com.google.cloud.bigtable.data.v2.BigtableDataClient)2 DefaultRowAdapter (com.google.cloud.bigtable.data.v2.models.DefaultRowAdapter)2 Filters (com.google.cloud.bigtable.data.v2.models.Filters)2 Filter (com.google.cloud.bigtable.data.v2.models.Filters.Filter)2 ServerStreamingStashCallable (com.google.cloud.bigtable.gaxx.testing.FakeStreamingApi.ServerStreamingStashCallable)2 Cell (org.apache.hadoop.hbase.Cell)2 Get (org.apache.hadoop.hbase.client.Get)2