Search in sources :

Example 11 with RequestContext

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

the class TestAppendAdapter method testMultipleAppends.

@Test
public void testMultipleAppends() {
    byte[] rowKey = dataHelper.randomData("rk1-");
    byte[] family1 = Bytes.toBytes("family1");
    byte[] qualifier1 = Bytes.toBytes("qualifier1");
    byte[] value1 = Bytes.toBytes("value1");
    byte[] family2 = Bytes.toBytes("family2");
    byte[] qualifier2 = Bytes.toBytes("qualifier2");
    byte[] value2 = Bytes.toBytes("value2");
    Append append = new Append(rowKey);
    append.add(family1, qualifier1, value1);
    append.add(family2, qualifier2, value2);
    ReadModifyWriteRow readModifyWriteRow = ReadModifyWriteRow.create(TABLE_ID, ByteString.copyFrom(rowKey));
    appendAdapter.adapt(append, readModifyWriteRow);
    ReadModifyWriteRowRequest request = readModifyWriteRow.toProto(requestContext);
    List<ReadModifyWriteRule> rules = request.getRulesList();
    Assert.assertEquals(2, rules.size());
    Assert.assertEquals("family1", rules.get(0).getFamilyName());
    Assert.assertEquals("qualifier1", rules.get(0).getColumnQualifier().toStringUtf8());
    Assert.assertEquals("value1", rules.get(0).getAppendValue().toStringUtf8());
    Assert.assertEquals("family2", rules.get(1).getFamilyName());
    Assert.assertEquals("qualifier2", rules.get(1).getColumnQualifier().toStringUtf8());
    Assert.assertEquals("value2", rules.get(1).getAppendValue().toStringUtf8());
}
Also used : Append(org.apache.hadoop.hbase.client.Append) ReadModifyWriteRowRequest(com.google.bigtable.v2.ReadModifyWriteRowRequest) ReadModifyWriteRule(com.google.bigtable.v2.ReadModifyWriteRule) ReadModifyWriteRow(com.google.cloud.bigtable.data.v2.models.ReadModifyWriteRow) Test(org.junit.Test)

Example 12 with RequestContext

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

the class TestPageFilterAdapter method pageFilterIsAppliedToReadRowsRequest.

@Test
public void pageFilterIsAppliedToReadRowsRequest() throws IOException {
    final String TABLE_ID = "tableId";
    final RequestContext requestContext = RequestContext.create("ProjectId", "InstanceId", "AppProfile");
    ReadHooks hooks = new DefaultReadHooks();
    FilterAdapterContext context = new FilterAdapterContext(new Scan(), hooks);
    PageFilter pageFilter = new PageFilter(20);
    Filters.Filter adaptedFilter = pageFilterAdapter.adapt(context, pageFilter);
    Assert.assertNull("PageFilterAdapter should not return a Filters.Filter.", adaptedFilter);
    Query query = Query.create(TABLE_ID).limit(100);
    hooks.applyPreSendHook(query);
    Assert.assertEquals(20, query.toProto(requestContext).getRowsLimit());
}
Also used : Filters(com.google.cloud.bigtable.data.v2.models.Filters) ReadHooks(com.google.cloud.bigtable.hbase.adapters.read.ReadHooks) DefaultReadHooks(com.google.cloud.bigtable.hbase.adapters.read.DefaultReadHooks) Query(com.google.cloud.bigtable.data.v2.models.Query) Scan(org.apache.hadoop.hbase.client.Scan) PageFilter(org.apache.hadoop.hbase.filter.PageFilter) RequestContext(com.google.cloud.bigtable.data.v2.internal.RequestContext) DefaultReadHooks(com.google.cloud.bigtable.hbase.adapters.read.DefaultReadHooks) Test(org.junit.Test)

Example 13 with RequestContext

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

the class TestGetAdapter method testAdKeyOnlyFilterWithFilter.

@Test
public void testAdKeyOnlyFilterWithFilter() throws IOException {
    Get get = makeValidGet(dataHelper.randomData(PREFIX_DATA));
    get.setCheckExistenceOnly(true);
    get.setFilter(new KeyOnlyFilter());
    getAdapter.adapt(get, throwingReadHooks, query);
    Filters.Filter filterOne = FILTERS.chain().filter(FILTERS.limit().cellsPerColumn(1)).filter(FILTERS.value().strip());
    Filters.Filter filterTwo = FILTERS.chain().filter(FILTERS.limit().cellsPerColumn(1)).filter(FILTERS.value().strip());
    Assert.assertEquals(FILTERS.chain().filter(filterOne).filter(filterTwo).toProto(), query.toProto(requestContext).getFilter());
}
Also used : KeyOnlyFilter(org.apache.hadoop.hbase.filter.KeyOnlyFilter) Filters(com.google.cloud.bigtable.data.v2.models.Filters) Get(org.apache.hadoop.hbase.client.Get) Test(org.junit.Test)

Example 14 with RequestContext

use of com.google.cloud.bigtable.data.v2.internal.RequestContext in project java-bigtable by googleapis.

the class MutateRowsBatchingDescriptorTest method requestBuilderTest.

@Test
public void requestBuilderTest() {
    MutateRowsBatchingDescriptor underTest = new MutateRowsBatchingDescriptor();
    long timestamp = 10_000L;
    BulkMutation bulkMutation = BulkMutation.create("fake-table");
    BatchingRequestBuilder<RowMutationEntry, BulkMutation> requestBuilder = underTest.newRequestBuilder(bulkMutation);
    requestBuilder.add(RowMutationEntry.create(ROW_KEY).setCell(FAMILY, QUALIFIER, timestamp, VALUE));
    requestBuilder.add(RowMutationEntry.create("rowKey-2").setCell("family-2", "q", 20_000L, "some-value"));
    BulkMutation actualBulkMutation = requestBuilder.build();
    assertThat(actualBulkMutation.toProto(requestContext)).isEqualTo(BulkMutation.create("fake-table").add(ROW_KEY, Mutation.create().setCell(FAMILY, QUALIFIER, timestamp, VALUE)).add("rowKey-2", Mutation.create().setCell("family-2", "q", 20_000L, "some-value")).toProto(requestContext));
}
Also used : BulkMutation(com.google.cloud.bigtable.data.v2.models.BulkMutation) RowMutationEntry(com.google.cloud.bigtable.data.v2.models.RowMutationEntry) Test(org.junit.Test)

Example 15 with RequestContext

use of com.google.cloud.bigtable.data.v2.internal.RequestContext in project java-bigtable by googleapis.

the class EnhancedBigtableStub method createReadModifyWriteRowCallable.

/**
 * Creates a callable chain to handle ReadModifyWriteRow RPCs. The chain will:
 *
 * <ul>
 *   <li>Convert {@link ReadModifyWriteRow}s into {@link
 *       com.google.bigtable.v2.ReadModifyWriteRowRequest}s.
 *   <li>Convert the responses into {@link Row}.
 *   <li>Add tracing & metrics.
 * </ul>
 */
private UnaryCallable<ReadModifyWriteRow, Row> createReadModifyWriteRowCallable() {
    UnaryCallable<ReadModifyWriteRowRequest, ReadModifyWriteRowResponse> base = GrpcRawCallableFactory.createUnaryCallable(GrpcCallSettings.<ReadModifyWriteRowRequest, ReadModifyWriteRowResponse>newBuilder().setMethodDescriptor(BigtableGrpc.getReadModifyWriteRowMethod()).setParamsExtractor(new RequestParamsExtractor<ReadModifyWriteRowRequest>() {

        @Override
        public Map<String, String> extract(ReadModifyWriteRowRequest request) {
            return ImmutableMap.of("table_name", request.getTableName(), "app_profile_id", request.getAppProfileId());
        }
    }).build(), settings.readModifyWriteRowSettings().getRetryableCodes());
    UnaryCallable<ReadModifyWriteRowRequest, ReadModifyWriteRowResponse> withStatsHeaders = new StatsHeadersUnaryCallable<>(base);
    String methodName = "ReadModifyWriteRow";
    UnaryCallable<ReadModifyWriteRowRequest, ReadModifyWriteRowResponse> withHeaderTracer = new HeaderTracerUnaryCallable<>(withStatsHeaders);
    UnaryCallable<ReadModifyWriteRowRequest, ReadModifyWriteRowResponse> retrying = Callables.retrying(withHeaderTracer, settings.readModifyWriteRowSettings(), clientContext);
    return createUserFacingUnaryCallable(methodName, new ReadModifyWriteRowCallable(retrying, requestContext));
}
Also used : HeaderTracerUnaryCallable(com.google.cloud.bigtable.data.v2.stub.metrics.HeaderTracerUnaryCallable) ReadModifyWriteRowRequest(com.google.bigtable.v2.ReadModifyWriteRowRequest) StatsHeadersUnaryCallable(com.google.cloud.bigtable.data.v2.stub.metrics.StatsHeadersUnaryCallable) ByteString(com.google.protobuf.ByteString) ReadModifyWriteRowResponse(com.google.bigtable.v2.ReadModifyWriteRowResponse) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap)

Aggregations

Test (org.junit.Test)12 ReadModifyWriteRowRequest (com.google.bigtable.v2.ReadModifyWriteRowRequest)9 ReadModifyWriteRow (com.google.cloud.bigtable.data.v2.models.ReadModifyWriteRow)8 ByteString (com.google.protobuf.ByteString)7 ReadModifyWriteRule (com.google.bigtable.v2.ReadModifyWriteRule)6 HeaderTracerUnaryCallable (com.google.cloud.bigtable.data.v2.stub.metrics.HeaderTracerUnaryCallable)6 StatsHeadersUnaryCallable (com.google.cloud.bigtable.data.v2.stub.metrics.StatsHeadersUnaryCallable)4 ImmutableMap (com.google.common.collect.ImmutableMap)4 Map (java.util.Map)4 Append (org.apache.hadoop.hbase.client.Append)4 Increment (org.apache.hadoop.hbase.client.Increment)4 SpanName (com.google.api.gax.tracing.SpanName)3 Filters (com.google.cloud.bigtable.data.v2.models.Filters)3 Query (com.google.cloud.bigtable.data.v2.models.Query)3 TracedUnaryCallable (com.google.api.gax.tracing.TracedUnaryCallable)2 CheckAndMutateRowRequest (com.google.bigtable.v2.CheckAndMutateRowRequest)2 CheckAndMutateRowResponse (com.google.bigtable.v2.CheckAndMutateRowResponse)2 ReadRowsRequest (com.google.bigtable.v2.ReadRowsRequest)2 BulkMutation (com.google.cloud.bigtable.data.v2.models.BulkMutation)2 TracedBatcherUnaryCallable (com.google.cloud.bigtable.data.v2.stub.metrics.TracedBatcherUnaryCallable)2