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());
}
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);
}
};
}
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());
}
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;
}
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();
}
Aggregations