Search in sources :

Example 96 with Row

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

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

the class Reads method readRowPartial.

public static void readRowPartial(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";
        Filters.Filter filter = FILTERS.chain().filter(FILTERS.family().exactMatch("stats_summary")).filter(FILTERS.qualifier().exactMatch("os_build"));
        Row row = dataClient.readRow(tableId, rowkey, filter);
        printRow(row);
    } catch (IOException e) {
        System.out.println("Unable to initialize service client, as a network error occurred: \n" + e.toString());
    }
}
Also used : Filters(com.google.cloud.bigtable.data.v2.models.Filters) Row(com.google.cloud.bigtable.data.v2.models.Row) IOException(java.io.IOException) BigtableDataClient(com.google.cloud.bigtable.data.v2.BigtableDataClient)

Example 98 with Row

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

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

the class Reads method readPrefix.

public static void readPrefix(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).prefix("phone");
        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 100 with Row

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

the class EnhancedBigtableStubTest method testCallContextPropagatedInReadBatcher.

@Test
public void testCallContextPropagatedInReadBatcher() throws IOException, InterruptedException, ExecutionException {
    EnhancedBigtableStubSettings settings = defaultSettings.toBuilder().setRefreshingChannel(true).setPrimedTableIds("table1", "table2").build();
    try (EnhancedBigtableStub stub = EnhancedBigtableStub.create(settings)) {
        // clear the previous contexts
        contextInterceptor.contexts.clear();
        // Override the timeout
        GrpcCallContext clientCtx = GrpcCallContext.createDefault().withTimeout(Duration.ofMinutes(10));
        // Send a batch
        try (Batcher<ByteString, Row> batcher = stub.newBulkReadRowsBatcher(Query.create("table1"), clientCtx)) {
            batcher.add(ByteString.copyFromUtf8("key")).get();
        }
        // Ensure that the server got the overriden deadline
        Context serverCtx = contextInterceptor.contexts.poll();
        assertThat(serverCtx).isNotNull();
        assertThat(serverCtx.getDeadline()).isAtLeast(Deadline.after(8, TimeUnit.MINUTES));
    }
}
Also used : GrpcCallContext(com.google.api.gax.grpc.GrpcCallContext) Context(io.grpc.Context) RequestContext(com.google.cloud.bigtable.data.v2.internal.RequestContext) GrpcCallContext(com.google.api.gax.grpc.GrpcCallContext) ByteString(com.google.protobuf.ByteString) Row(com.google.cloud.bigtable.data.v2.models.Row) 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