Search in sources :

Example 11 with Row

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

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

the class AbstractBigtableTable method checkAndDelete.

/**
 * {@inheritDoc}
 */
@Override
public boolean checkAndDelete(byte[] row, byte[] family, byte[] qualifier, CompareFilter.CompareOp compareOp, byte[] value, Delete delete) throws IOException {
    LOG.trace("checkAndDelete(byte[], byte[], byte[], CompareOp, byte[], Delete)");
    ConditionalRowMutation request = new CheckAndMutateUtil.RequestBuilder(hbaseAdapter, row, family).qualifier(qualifier).ifMatches(compareOp, value).withDelete(delete).build();
    return checkAndMutate(row, request, "checkAndDelete");
}
Also used : ConditionalRowMutation(com.google.cloud.bigtable.data.v2.models.ConditionalRowMutation)

Example 13 with Row

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

the class BigtableTable method checkAndMutate.

@Override
public CheckAndMutateBuilder checkAndMutate(byte[] row, byte[] family) {
    final CheckAndMutateUtil.RequestBuilder builder = new CheckAndMutateUtil.RequestBuilder(hbaseAdapter, row, family);
    return new CheckAndMutateBuilder() {

        /**
         * {@inheritDoc}
         */
        @Override
        public CheckAndMutateBuilder qualifier(byte[] qualifier) {
            builder.qualifier(qualifier);
            return this;
        }

        /**
         * {@inheritDoc}
         */
        @Override
        public CheckAndMutateBuilder ifNotExists() {
            builder.ifNotExists();
            return this;
        }

        /**
         * {@inheritDoc}
         */
        @Override
        public CheckAndMutateBuilder ifMatches(CompareOperator compareOp, byte[] value) {
            Preconditions.checkNotNull(compareOp, "compareOp is null");
            if (compareOp != CompareOperator.NOT_EQUAL) {
                Preconditions.checkNotNull(value, "value is null for compareOperator: " + compareOp);
            }
            builder.ifMatches(BigtableTable.toCompareOp(compareOp), value);
            return this;
        }

        /**
         * {@inheritDoc}
         */
        public CheckAndMutateBuilder timeRange(TimeRange timeRange) {
            builder.timeRange(timeRange.getMin(), timeRange.getMax());
            return this;
        }

        /**
         * {@inheritDoc}
         */
        @Override
        public boolean thenPut(Put put) throws IOException {
            try {
                builder.withPut(put);
                return call();
            } catch (Exception e) {
                throw new IOException("Could not CheckAndMutate.thenPut: " + e.getMessage(), e);
            }
        }

        /**
         * {@inheritDoc}
         */
        @Override
        public boolean thenDelete(Delete delete) throws IOException {
            try {
                builder.withDelete(delete);
                return call();
            } catch (Exception e) {
                throw new IOException("Could not CheckAndMutate.thenDelete: " + e.getMessage(), e);
            }
        }

        /**
         * {@inheritDoc}
         */
        @Override
        public boolean thenMutate(RowMutations rowMutations) throws IOException {
            try {
                builder.withMutations(rowMutations);
                return call();
            } catch (Exception e) {
                throw new IOException("Could not CheckAndMutate.thenMutate: " + e.getMessage(), e);
            }
        }

        private boolean call() throws IOException {
            ConditionalRowMutation conditionalRowMutation = builder.build();
            Boolean response = FutureUtil.unwrap(clientWrapper.checkAndMutateRowAsync(conditionalRowMutation));
            return CheckAndMutateUtil.wasMutationApplied(conditionalRowMutation, response);
        }
    };
}
Also used : Delete(org.apache.hadoop.hbase.client.Delete) IOException(java.io.IOException) Put(org.apache.hadoop.hbase.client.Put) IOException(java.io.IOException) RowMutations(org.apache.hadoop.hbase.client.RowMutations) CompareOperator(org.apache.hadoop.hbase.CompareOperator) CheckAndMutateUtil(com.google.cloud.bigtable.hbase.adapters.CheckAndMutateUtil) TimeRange(org.apache.hadoop.hbase.io.TimeRange) ConditionalRowMutation(com.google.cloud.bigtable.data.v2.models.ConditionalRowMutation)

Example 14 with Row

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

the class ColumnPaginationFilterAdapter method createChain.

/**
 * Create a filter chain that allows the latest values for each qualifier, those cells that pass
 * an option intermediate filter and are less than the limit per row.
 */
private Filter createChain(ColumnPaginationFilter filter, Filter intermediate) {
    ChainFilter chain = FILTERS.chain();
    chain.filter(FILTERS.limit().cellsPerColumn(1));
    if (intermediate != null) {
        chain.filter(intermediate);
    }
    chain.filter(FILTERS.limit().cellsPerRow(filter.getLimit()));
    return chain;
}
Also used : ChainFilter(com.google.cloud.bigtable.data.v2.models.Filters.ChainFilter)

Example 15 with Row

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

the class TestDataClientVeneerApi method testReadRowAsync.

@Test
public void testReadRowAsync() throws Exception {
    Query expectedRequest = Query.create(TABLE_ID).rowKey(ROW_KEY).limit(1);
    UnaryCallable<Query, Row> mockCallable = Mockito.mock(UnaryCallable.class);
    when(mockCallable.futureCall(Mockito.eq(expectedRequest), Mockito.any(GrpcCallContext.class))).thenReturn(ApiFutures.immediateFuture(MODEL_ROW));
    when(mockDataClient.readRowCallable()).thenReturn(mockCallable);
    Result actualResult = dataClientWrapper.readRowAsync(TABLE_ID, ROW_KEY, null).get();
    assertResult(EXPECTED_RESULT, actualResult);
    verify(mockCallable).futureCall(Mockito.eq(expectedRequest), Mockito.any(GrpcCallContext.class));
}
Also used : GrpcCallContext(com.google.api.gax.grpc.GrpcCallContext) 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) Result(org.apache.hadoop.hbase.client.Result) 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