Search in sources :

Example 41 with Row

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

the class Reads method readRow.

public static void readRow(String projectId, String instanceId, String tableId) {
    // the "close" method on the client to safely clean up any remaining background resources.
    try (BigtableDataClient dataClient = BigtableDataClient.create(projectId, instanceId)) {
        String rowkey = "phone#4c410523#20190501";
        Row row = dataClient.readRow(tableId, rowkey);
        printRow(row);
    } catch (IOException e) {
        System.out.println("Unable to initialize service client, as a network error occurred: \n" + e.toString());
    }
}
Also used : Row(com.google.cloud.bigtable.data.v2.models.Row) IOException(java.io.IOException) BigtableDataClient(com.google.cloud.bigtable.data.v2.BigtableDataClient)

Example 42 with Row

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

the class Reads method printRow.

// [END bigtable_reads_filter]
// [END_EXCLUDE]
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);
        }
        System.out.printf("\t%s: %s @%s%n", cell.getQualifier().toStringUtf8(), cell.getValue().toStringUtf8(), cell.getTimestamp());
    }
    System.out.println();
}
Also used : RowCell(com.google.cloud.bigtable.data.v2.models.RowCell)

Example 43 with Row

use of com.google.cloud.bigtable.data.v2.models.Row 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 44 with Row

use of com.google.cloud.bigtable.data.v2.models.Row 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 45 with Row

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

the class BigtableDataClientTests method existsAsyncTest.

@Test
public void existsAsyncTest() throws Exception {
    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));
    ApiFuture<Boolean> result = bigtableDataClient.existsAsync("fake-table", ByteString.copyFromUtf8("fake-row-key"));
    assertThat(result.get()).isTrue();
    ApiFuture<Boolean> anotherResult = bigtableDataClient.existsAsync("fake-table", "fake-row-key");
    assertThat(anotherResult.get()).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)

Aggregations

Row (com.google.cloud.bigtable.data.v2.models.Row)71 Test (org.junit.Test)64 Query (com.google.cloud.bigtable.data.v2.models.Query)34 ByteString (com.google.protobuf.ByteString)28 ReadModifyWriteRow (com.google.cloud.bigtable.data.v2.models.ReadModifyWriteRow)26 BigtableDataClient (com.google.cloud.bigtable.data.v2.BigtableDataClient)19 RowCell (com.google.cloud.bigtable.data.v2.models.RowCell)19 ReadRowsRequest (com.google.bigtable.v2.ReadRowsRequest)13 Filter (com.google.cloud.bigtable.data.v2.models.Filters.Filter)11 IOException (java.io.IOException)10 RowMutation (com.google.cloud.bigtable.data.v2.models.RowMutation)9 ServerStreamingStashCallable (com.google.cloud.bigtable.gaxx.testing.FakeStreamingApi.ServerStreamingStashCallable)7 Put (org.apache.hadoop.hbase.client.Put)7 DefaultRowAdapter (com.google.cloud.bigtable.data.v2.models.DefaultRowAdapter)6 MutateRowRequest (com.google.bigtable.v2.MutateRowRequest)5 Mutation (com.google.bigtable.v2.Mutation)5 SetCell (com.google.bigtable.v2.Mutation.SetCell)5 NotFoundException (com.google.api.gax.rpc.NotFoundException)4 ReadRowsResponse (com.google.bigtable.v2.ReadRowsResponse)4 ConditionalRowMutation (com.google.cloud.bigtable.data.v2.models.ConditionalRowMutation)4