Search in sources :

Example 1 with RowCell

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

the class CassandraMigrationCodelab method get.

public void get() {
    try {
        String rowKey = "phone#4c410523#20190501";
        Row row = dataClient.readRow(tableId, rowKey);
        for (RowCell cell : row.getCells()) {
            System.out.printf("Family: %s    Qualifier: %s    Value: %s    Timestamp: %s%n", cell.getFamily(), cell.getQualifier().toStringUtf8(), cell.getValue().toStringUtf8(), cell.getTimestamp());
        }
    } catch (Exception e) {
        System.out.println("Error during lookup: \n" + e.toString());
    }
}
Also used : RowCell(com.google.cloud.bigtable.data.v2.models.RowCell) ByteString(com.google.protobuf.ByteString) Row(com.google.cloud.bigtable.data.v2.models.Row)

Example 2 with RowCell

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

the class CassandraMigrationCodelab method scan.

public void scan() {
    try {
        Query query = Query.create(tableId).range("tablet#a0b81f74#201905", "tablet#a0b81f74#201906");
        ServerStream<Row> rowStream = dataClient.readRows(query);
        for (Row row : rowStream) {
            System.out.println("Row Key: " + row.getKey().toStringUtf8());
            for (RowCell cell : row.getCells()) {
                System.out.printf("Family: %s    Qualifier: %s    Value: %s    Timestamp: %s%n", cell.getFamily(), cell.getQualifier().toStringUtf8(), cell.getValue().toStringUtf8(), cell.getTimestamp());
            }
        }
    } catch (Exception e) {
        System.out.println("Error during scan: \n" + e.toString());
    }
}
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 3 with RowCell

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

the class BigtableEmulatorContainerTest method testSimple.

// }
@Test
public // testWithEmulatorContainer {
void testSimple() throws IOException, InterruptedException, ExecutionException {
    ManagedChannel channel = ManagedChannelBuilder.forTarget(emulator.getEmulatorEndpoint()).usePlaintext().build();
    TransportChannelProvider channelProvider = FixedTransportChannelProvider.create(GrpcTransportChannel.create(channel));
    NoCredentialsProvider credentialsProvider = NoCredentialsProvider.create();
    try {
        createTable(channelProvider, credentialsProvider, "test-table");
        BigtableDataClient client = BigtableDataClient.create(BigtableDataSettings.newBuilderForEmulator(emulator.getHost(), emulator.getEmulatorPort()).setProjectId(PROJECT_ID).setInstanceId(INSTANCE_ID).build());
        client.mutateRow(RowMutation.create("test-table", "1").setCell("name", "firstName", "Ray"));
        Row row = client.readRow("test-table", "1");
        List<RowCell> cells = row.getCells("name", "firstName");
        assertThat(cells).isNotNull().hasSize(1);
        assertThat(cells.get(0).getValue().toStringUtf8()).isEqualTo("Ray");
    } finally {
        channel.shutdown();
    }
}
Also used : NoCredentialsProvider(com.google.api.gax.core.NoCredentialsProvider) ManagedChannel(io.grpc.ManagedChannel) RowCell(com.google.cloud.bigtable.data.v2.models.RowCell) Row(com.google.cloud.bigtable.data.v2.models.Row) FixedTransportChannelProvider(com.google.api.gax.rpc.FixedTransportChannelProvider) TransportChannelProvider(com.google.api.gax.rpc.TransportChannelProvider) BigtableDataClient(com.google.cloud.bigtable.data.v2.BigtableDataClient) Test(org.junit.Test)

Example 4 with RowCell

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

the class TestRowResultAdapter method testWithSingleCellRow.

@Test
public void testWithSingleCellRow() {
    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.startCell(COL_FAMILY, QUAL_TWO, 20000L, LABELS, -1);
    rowBuilder.cellValue(VALUE);
    rowBuilder.finishCell();
    Result expected = Result.create(ImmutableList.<Cell>of(new RowCell(ROW_KEY.toByteArray(), COL_FAMILY.getBytes(), QUAL_ONE.toByteArray(), 10L, VALUE.toByteArray()), new RowCell(ROW_KEY.toByteArray(), COL_FAMILY.getBytes(), QUAL_TWO.toByteArray(), 20L, VALUE.toByteArray(), LABELS)));
    assertResult(expected, rowBuilder.finishRow());
    assertEquals(ROW_KEY, underTest.getKey(expected));
}
Also used : RowAdapter(com.google.cloud.bigtable.data.v2.models.RowAdapter) RowCell(com.google.cloud.bigtable.hbase.adapters.read.RowCell) Result(org.apache.hadoop.hbase.client.Result) Test(org.junit.Test)

Example 5 with RowCell

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

the class TestRowResultAdapter method testOnlyValueIsDifferent.

@Test
public void testOnlyValueIsDifferent() {
    ByteString valuePart1 = ByteString.copyFromUtf8("part-1");
    RowAdapter.RowBuilder<Result> rowBuilder = underTest.createRowBuilder();
    rowBuilder.startRow(ROW_KEY);
    rowBuilder.startCell(COL_FAMILY, QUAL_ONE, 30000L, LABELS, VALUE.size());
    rowBuilder.cellValue(VALUE);
    rowBuilder.finishCell();
    // started cell with same qualifier but different value
    rowBuilder.startCell(COL_FAMILY, QUAL_ONE, 30000L, LABELS, valuePart1.size());
    rowBuilder.cellValue(valuePart1);
    rowBuilder.finishCell();
    Result actual = rowBuilder.finishRow();
    assertEquals(2, actual.size());
    Result expected = Result.create(ImmutableList.<Cell>of(new RowCell(ROW_KEY.toByteArray(), COL_FAMILY.getBytes(), QUAL_ONE.toByteArray(), 30L, VALUE.toByteArray(), LABELS), new RowCell(ROW_KEY.toByteArray(), COL_FAMILY.getBytes(), QUAL_ONE.toByteArray(), 30L, valuePart1.toByteArray(), LABELS)));
    assertResult(expected, actual);
}
Also used : ByteString(com.google.protobuf.ByteString) RowAdapter(com.google.cloud.bigtable.data.v2.models.RowAdapter) RowCell(com.google.cloud.bigtable.hbase.adapters.read.RowCell) Result(org.apache.hadoop.hbase.client.Result) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)22 Row (com.google.cloud.bigtable.data.v2.models.Row)20 RowCell (com.google.cloud.bigtable.data.v2.models.RowCell)15 ByteString (com.google.protobuf.ByteString)10 Result (org.apache.hadoop.hbase.client.Result)10 Query (com.google.cloud.bigtable.data.v2.models.Query)9 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