Search in sources :

Example 1 with Builder

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

the class TestFuzzyRowFilterAdapter method fuzzyKeysAreTranslatedToRegularExpressions.

@Test
public void fuzzyKeysAreTranslatedToRegularExpressions() throws IOException {
    List<Pair<byte[], byte[]>> testPairs = ImmutableList.<Pair<byte[], byte[]>>builder().add(new Pair<>(Bytes.toBytes("abcd"), new byte[] { -1, -1, -1, -1 })).add(new Pair<>(Bytes.toBytes(".fgh"), new byte[] { 0, 0, 1, 0 })).add(new Pair<>(Bytes.toBytes("ijkl"), new byte[] { 1, 1, 1, 1 })).build();
    FuzzyRowFilter filter = new FuzzyRowFilter(testPairs);
    Filters.Filter adaptedFilter = adapter.adapt(context, filter);
    Filters.Filter expected = FILTERS.interleave().filter(FILTERS.key().regex("abcd\\C*")).filter(FILTERS.key().regex("\\.f\\Ch\\C*")).filter(FILTERS.key().regex("\\C\\C\\C\\C\\C*"));
    Assert.assertEquals(expected.toProto(), adaptedFilter.toProto());
}
Also used : Filters(com.google.cloud.bigtable.data.v2.models.Filters) FuzzyRowFilter(org.apache.hadoop.hbase.filter.FuzzyRowFilter) Pair(org.apache.hadoop.hbase.util.Pair) Test(org.junit.Test)

Example 2 with Builder

use of com.google.cloud.bigtable.data.v2.BigtableDataSettings.Builder 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 3 with Builder

use of com.google.cloud.bigtable.data.v2.BigtableDataSettings.Builder in project java-bigtable by googleapis.

the class BigtableBatchingCallSettingsTest method testBuilderFromSettings.

@Test
public void testBuilderFromSettings() {
    BigtableBatchingCallSettings.Builder builder = BigtableBatchingCallSettings.newBuilder(new MutateRowsBatchingDescriptor());
    RetrySettings retrySettings = RetrySettings.newBuilder().setTotalTimeout(Duration.ofMinutes(1)).build();
    builder.setBatchingSettings(BATCHING_SETTINGS).setRetryableCodes(StatusCode.Code.UNAVAILABLE, StatusCode.Code.UNAUTHENTICATED).setRetrySettings(retrySettings).enableLatencyBasedThrottling(10L);
    BigtableBatchingCallSettings settings = builder.build();
    BigtableBatchingCallSettings.Builder newBuilder = settings.toBuilder();
    assertThat(newBuilder.getBatchingSettings()).isEqualTo(BATCHING_SETTINGS);
    assertThat(newBuilder.getRetryableCodes()).containsExactly(StatusCode.Code.UNAVAILABLE, StatusCode.Code.UNAUTHENTICATED);
    assertThat(newBuilder.getRetrySettings()).isEqualTo(retrySettings);
    assertThat(newBuilder.isLatencyBasedThrottlingEnabled()).isTrue();
    assertThat(newBuilder.getTargetRpcLatencyMs()).isEqualTo(10L);
    assertThat(newBuilder.getDynamicFlowControlSettings()).isNotNull();
    verifyFlowControlSettingWhenLatencyBasedThrottlingEnabled(newBuilder.getDynamicFlowControlSettings());
}
Also used : RetrySettings(com.google.api.gax.retrying.RetrySettings) MutateRowsBatchingDescriptor(com.google.cloud.bigtable.data.v2.stub.mutaterows.MutateRowsBatchingDescriptor) Test(org.junit.Test)

Example 4 with Builder

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

the class SingleColumnValueFilterAdapter method getColumnSpecFilter.

@VisibleForTesting
static ChainFilter getColumnSpecFilter(byte[] family, byte[] qualifier, boolean latestVersionOnly) throws IOException {
    ByteString wrappedQual = quoteRegularExpression(qualifier);
    String wrappedFamily = quoteRegularExpression(family).toStringUtf8();
    ChainFilter builder = FILTERS.chain().filter(FILTERS.family().regex(wrappedFamily)).filter(FILTERS.qualifier().regex(wrappedQual));
    if (latestVersionOnly) {
        builder.filter(LATEST_ONLY_FILTER);
    }
    return builder;
}
Also used : ByteString(com.google.protobuf.ByteString) ByteString(com.google.protobuf.ByteString) ChainFilter(com.google.cloud.bigtable.data.v2.models.Filters.ChainFilter) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 5 with Builder

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

the class TestRowMutationsAdapter method toMutateRowRequest.

private MutateRowRequest toMutateRowRequest(byte[] rowKey, com.google.cloud.bigtable.data.v2.models.Mutation mutation) {
    RowMutation rowMutation = toRowMutationModel(rowKey, mutation);
    MutateRowRequest.Builder builder = rowMutation.toProto(REQUEST_CONTEXT).toBuilder();
    return builder.build();
}
Also used : MutateRowRequest(com.google.bigtable.v2.MutateRowRequest) RowMutation(com.google.cloud.bigtable.data.v2.models.RowMutation)

Aggregations

Test (org.junit.Test)9 RetrySettings (com.google.api.gax.retrying.RetrySettings)4 BigtableDataSettings (com.google.cloud.bigtable.data.v2.BigtableDataSettings)3 MutateRowsBatchingDescriptor (com.google.cloud.bigtable.data.v2.stub.mutaterows.MutateRowsBatchingDescriptor)3 ReadRowsBatchingDescriptor (com.google.cloud.bigtable.data.v2.stub.readrows.ReadRowsBatchingDescriptor)3 InstantiatingGrpcChannelProvider (com.google.api.gax.grpc.InstantiatingGrpcChannelProvider)2 StatusCode (com.google.api.gax.rpc.StatusCode)2 MutateRowsRequest (com.google.bigtable.v2.MutateRowsRequest)2 Builder (com.google.bigtable.v2.MutateRowsRequest.Builder)2 Filters (com.google.cloud.bigtable.data.v2.models.Filters)2 MutateRowsException (com.google.cloud.bigtable.data.v2.models.MutateRowsException)2 FailedMutation (com.google.cloud.bigtable.data.v2.models.MutateRowsException.FailedMutation)2 ApiFunction (com.google.api.core.ApiFunction)1 BatcherImpl (com.google.api.gax.batching.BatcherImpl)1 FlowControlEventStats (com.google.api.gax.batching.FlowControlEventStats)1 ApiException (com.google.api.gax.rpc.ApiException)1 ClientContext (com.google.api.gax.rpc.ClientContext)1 OpencensusTracerFactory (com.google.api.gax.tracing.OpencensusTracerFactory)1 Credentials (com.google.auth.Credentials)1 ServiceAccountJwtAccessCredentials (com.google.auth.oauth2.ServiceAccountJwtAccessCredentials)1