Search in sources :

Example 11 with Query

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

the class BigtableDataClientTest method proxyReadRowsAsyncTest.

@Test
public void proxyReadRowsAsyncTest() {
    Mockito.when(mockStub.readRowsCallable()).thenReturn(mockReadRowsCallable);
    Query query = Query.create("fake-table");
    @SuppressWarnings("unchecked") ResponseObserver<Row> mockObserver = Mockito.mock(ResponseObserver.class);
    bigtableDataClient.readRowsAsync(query, mockObserver);
    Mockito.verify(mockReadRowsCallable).call(query, mockObserver);
}
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 12 with Query

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

the class BigtableDataClientTest method proxyReadRowsSyncTest.

@Test
public void proxyReadRowsSyncTest() {
    Mockito.when(mockStub.readRowsCallable()).thenReturn(mockReadRowsCallable);
    Query query = Query.create("fake-table");
    bigtableDataClient.readRows(query);
    Mockito.verify(mockReadRowsCallable).call(query);
}
Also used : Query(com.google.cloud.bigtable.data.v2.models.Query) Test(org.junit.Test)

Example 13 with Query

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

the class ReadRowsRetryTest method getResults.

private List<String> getResults(Query query) {
    ServerStream<Row> actualRows = client.readRows(query);
    List<String> actualValues = Lists.newArrayList();
    for (Row row : actualRows) {
        actualValues.add(row.getKey().toStringUtf8());
    }
    return actualValues;
}
Also used : Row(com.google.cloud.bigtable.data.v2.models.Row) ByteString(com.google.protobuf.ByteString)

Example 14 with Query

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

the class HelloWorld method readTable.

/**
 * Demonstrates how to read an entire table.
 */
public List<Row> readTable() {
    // [START bigtable_hw_scan_all]
    try {
        System.out.println("\nReading the entire table");
        Query query = Query.create(tableId);
        ServerStream<Row> rowStream = dataClient.readRows(query);
        List<Row> tableRows = new ArrayList<>();
        for (Row r : rowStream) {
            System.out.println("Row Key: " + r.getKey().toStringUtf8());
            tableRows.add(r);
            for (RowCell cell : r.getCells()) {
                System.out.printf("Family: %s    Qualifier: %s    Value: %s%n", cell.getFamily(), cell.getQualifier().toStringUtf8(), cell.getValue().toStringUtf8());
            }
        }
        return tableRows;
    } catch (NotFoundException e) {
        System.err.println("Failed to read a non-existent table: " + e.getMessage());
        return null;
    }
// [END bigtable_hw_scan_all]
}
Also used : Query(com.google.cloud.bigtable.data.v2.models.Query) ArrayList(java.util.ArrayList) 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)

Example 15 with Query

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

the class Reads method readRowRanges.

public static void readRowRanges(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)) {
        Query query = Query.create(tableId).range("phone#4c410523#20190501", "phone#4c410523#20190601").range("phone#5c10102#20190501", "phone#5c10102#20190601");
        ServerStream<Row> rows = dataClient.readRows(query);
        for (Row row : rows) {
            printRow(row);
        }
    } catch (IOException e) {
        System.out.println("Unable to initialize service client, as a network error occurred: \n" + e.toString());
    }
}
Also used : Query(com.google.cloud.bigtable.data.v2.models.Query) Row(com.google.cloud.bigtable.data.v2.models.Row) IOException(java.io.IOException) BigtableDataClient(com.google.cloud.bigtable.data.v2.BigtableDataClient)

Aggregations

Query (com.google.cloud.bigtable.data.v2.models.Query)34 Row (com.google.cloud.bigtable.data.v2.models.Row)24 Test (org.junit.Test)20 ReadRowsRequest (com.google.bigtable.v2.ReadRowsRequest)7 BigtableDataClient (com.google.cloud.bigtable.data.v2.BigtableDataClient)7 IOException (java.io.IOException)7 ReadModifyWriteRow (com.google.cloud.bigtable.data.v2.models.ReadModifyWriteRow)5 ByteString (com.google.protobuf.ByteString)5 Result (org.apache.hadoop.hbase.client.Result)5 GrpcCallContext (com.google.api.gax.grpc.GrpcCallContext)4 Filters (com.google.cloud.bigtable.data.v2.models.Filters)4 RowCell (com.google.cloud.bigtable.data.v2.models.RowCell)4 DefaultReadHooks (com.google.cloud.bigtable.hbase.adapters.read.DefaultReadHooks)3 ReadHooks (com.google.cloud.bigtable.hbase.adapters.read.ReadHooks)3 SpanName (com.google.api.gax.tracing.SpanName)2 BulkMutation (com.google.cloud.bigtable.data.v2.models.BulkMutation)2 DefaultRowAdapter (com.google.cloud.bigtable.data.v2.models.DefaultRowAdapter)2 ReadRowsUserCallable (com.google.cloud.bigtable.data.v2.stub.readrows.ReadRowsUserCallable)2 ServerStreamingStashCallable (com.google.cloud.bigtable.gaxx.testing.FakeStreamingApi.ServerStreamingStashCallable)2 Scan (org.apache.hadoop.hbase.client.Scan)2