Search in sources :

Example 26 with Query

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

the class Filters method readFilter.

// [END bigtable_filters_composing_condition]
// [END_EXCLUDE]
private static void readFilter(String projectId, String instanceId, String tableId, Filter filter) {
    // 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).filter(filter);
        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)

Example 27 with Query

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

the class Reads method readRows.

public static void readRows(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).rowKey("phone#4c410523#20190501").rowKey("phone#4c410523#20190502");
        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)

Example 28 with Query

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

the class Reads method readRowRange.

public static void readRowRange(String projectId, String instanceId, String tableId) {
    String start = "phone#4c410523#20190501";
    String end = "phone#4c410523#201906201";
    // 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(start, end);
        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)

Example 29 with Query

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

the class ReadRowsBatchingDescriptorTest method requestBuilderTest.

@Test
public void requestBuilderTest() {
    BatchingRequestBuilder<ByteString, Query> requestBuilder = underTest.newRequestBuilder(Query.create("table-Id"));
    requestBuilder.add(ByteString.copyFromUtf8("row-key-1"));
    requestBuilder.add(ByteString.copyFromUtf8("row-key-2"));
    Query request = requestBuilder.build();
    ReadRowsRequest readRowsRequest = request.toProto(RequestContext.create("project", "instance", "appProfile"));
    assertThat(readRowsRequest.getTableName()).contains("table-Id");
    assertThat(readRowsRequest.getRows().getRowKeysList()).isEqualTo(ImmutableList.of(ByteString.copyFromUtf8("row-key-1"), ByteString.copyFromUtf8("row-key-2")));
}
Also used : Query(com.google.cloud.bigtable.data.v2.models.Query) ByteString(com.google.protobuf.ByteString) ReadRowsRequest(com.google.bigtable.v2.ReadRowsRequest) Test(org.junit.Test)

Example 30 with Query

use of com.google.cloud.bigtable.data.v2.models.Query 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)

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