use of com.google.bigtable.v2.ReadRowsRequest.Builder in project java-bigtable by googleapis.
the class ReadRowsResumptionStrategy method getResumeRequest.
/**
* {@inheritDoc}
*
* <p>Given a request, this implementation will narrow that request to exclude all row keys and
* ranges that would produce rows that come before {@link #lastKey}. Furthermore this
* implementation takes care to update the row limit of the request to account for all of the
* received rows.
*/
@Override
public ReadRowsRequest getResumeRequest(ReadRowsRequest originalRequest) {
// so resume with the original request object.
if (lastKey.isEmpty()) {
return originalRequest;
}
RowSet remaining = RowSetUtil.split(originalRequest.getRows(), lastKey).getRight();
// for more details.
if (remaining == null || (originalRequest.getRowsLimit() > 0 && originalRequest.getRowsLimit() == numProcessed)) {
return ReadRowsRetryCompletedCallable.FULFILLED_REQUEST_MARKER;
}
Builder builder = originalRequest.toBuilder().setRows(remaining);
if (originalRequest.getRowsLimit() > 0) {
Preconditions.checkState(originalRequest.getRowsLimit() > numProcessed, "Detected too many rows for the current row limit during a retry.");
builder.setRowsLimit(originalRequest.getRowsLimit() - numProcessed);
}
return builder.build();
}
use of com.google.bigtable.v2.ReadRowsRequest.Builder in project YCSB by brianfrankcooper.
the class GoogleBigtableClient method read.
@Override
public Status read(String table, String key, Set<String> fields, Map<String, ByteIterator> result) {
if (debug) {
System.out.println("Doing read from Bigtable columnfamily " + new String(columnFamilyBytes));
System.out.println("Doing read for key: " + key);
}
setTable(table);
RowFilter filter = RowFilter.newBuilder().setFamilyNameRegexFilterBytes(ByteStringer.wrap(columnFamilyBytes)).build();
if (fields != null && fields.size() > 0) {
Builder filterChain = RowFilter.Chain.newBuilder();
filterChain.addFilters(filter);
filterChain.addFilters(RowFilter.newBuilder().setCellsPerColumnLimitFilter(1).build());
int count = 0;
// usually "field#" so pre-alloc
final StringBuilder regex = new StringBuilder(fields.size() * 6);
for (final String field : fields) {
if (count++ > 0) {
regex.append("|");
}
regex.append(field);
}
filterChain.addFilters(RowFilter.newBuilder().setColumnQualifierRegexFilter(ByteStringer.wrap(regex.toString().getBytes()))).build();
filter = RowFilter.newBuilder().setChain(filterChain.build()).build();
}
final ReadRowsRequest.Builder rrr = ReadRowsRequest.newBuilder().setTableNameBytes(ByteStringer.wrap(lastTableBytes)).setFilter(filter).setRows(RowSet.newBuilder().addRowKeys(ByteStringer.wrap(key.getBytes())));
List<Row> rows;
try {
rows = client.readRowsAsync(rrr.build()).get();
if (rows == null || rows.isEmpty()) {
return Status.NOT_FOUND;
}
for (final Row row : rows) {
for (final Family family : row.getFamiliesList()) {
if (Arrays.equals(family.getNameBytes().toByteArray(), columnFamilyBytes)) {
for (final Column column : family.getColumnsList()) {
// we should only have a single cell per column
result.put(column.getQualifier().toString(UTF8_CHARSET), new ByteArrayByteIterator(column.getCells(0).getValue().toByteArray()));
if (debug) {
System.out.println("Result for field: " + column.getQualifier().toString(UTF8_CHARSET) + " is: " + column.getCells(0).getValue().toString(UTF8_CHARSET));
}
}
}
}
}
return Status.OK;
} catch (InterruptedException e) {
System.err.println("Interrupted during get: " + e);
Thread.currentThread().interrupt();
return Status.ERROR;
} catch (ExecutionException e) {
System.err.println("Exception during get: " + e);
return Status.ERROR;
}
}
use of com.google.bigtable.v2.ReadRowsRequest.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();
}
use of com.google.bigtable.v2.ReadRowsRequest.Builder in project java-bigtable-hbase by googleapis.
the class TestRowRangeAdapter method testLesserOrEqThan.
@Test
public void testLesserOrEqThan() {
ByteString key = ByteString.copyFromUtf8("hi");
RowSet in = RowSet.newBuilder().addRowRanges(RowRange.newBuilder().setEndKeyClosed(key)).build();
RangeSet<RowKeyWrapper> out = adapter.rowSetToRangeSet(in);
RangeSet<RowKeyWrapper> expected = ImmutableRangeSet.<RowKeyWrapper>builder().add(Range.atMost(new RowKeyWrapper(key))).build();
assertEquals(expected, out);
adapter.rangeSetToByteStringRange(out, query);
assertEquals(in, query.toProto(requestContext).getRows());
}
use of com.google.bigtable.v2.ReadRowsRequest.Builder in project java-bigtable-hbase by googleapis.
the class TestRowRangeAdapter method testGreaterOrEqThan.
@Test
public void testGreaterOrEqThan() {
ByteString key = ByteString.copyFromUtf8("hi");
RowSet in = RowSet.newBuilder().addRowRanges(RowRange.newBuilder().setStartKeyClosed(key)).build();
RangeSet<RowKeyWrapper> out = adapter.rowSetToRangeSet(in);
RangeSet<RowKeyWrapper> expected = ImmutableRangeSet.<RowKeyWrapper>builder().add(Range.atLeast(new RowKeyWrapper(key))).build();
assertEquals(expected, out);
adapter.rangeSetToByteStringRange(out, query);
assertEquals(in, query.toProto(requestContext).getRows());
}
Aggregations