use of com.palantir.atlasdb.keyvalue.api.RangeRequest in project atlasdb by palantir.
the class AbstractKeyValueServiceTest method doTestGetRangePagingWithColumnSelection.
private void doTestGetRangePagingWithColumnSelection(int batchSizeHint, int numRows, int numColsInSelection, boolean reverse) {
Collection<byte[]> columnSelection = new ArrayList<>(numColsInSelection);
for (long col = 1; col <= numColsInSelection; ++col) {
byte[] colName = PtBytes.toBytes(Long.MIN_VALUE ^ col);
columnSelection.add(colName);
}
RangeRequest request = RangeRequest.builder(reverse).retainColumns(columnSelection).batchHint(batchSizeHint).build();
try (ClosableIterator<RowResult<Value>> iter = keyValueService.getRange(TEST_TABLE, request, TEST_TIMESTAMP + 1)) {
List<RowResult<Value>> results = ImmutableList.copyOf(iter);
assertEquals(getExpectedResultForRangePagingWithColumnSelectionTest(numRows, numColsInSelection, reverse), results);
}
}
use of com.palantir.atlasdb.keyvalue.api.RangeRequest in project atlasdb by palantir.
the class AbstractKeyValueServiceTest method testGetRangeWithTimestamps.
private void testGetRangeWithTimestamps(boolean reverse) {
putTestDataForMultipleTimestamps();
final RangeRequest range;
if (!reverse) {
range = RangeRequest.builder().startRowInclusive(row0).endRowExclusive(row1).build();
} else {
range = RangeRequest.reverseBuilder().startRowInclusive(row0).build();
}
ClosableIterator<RowResult<Set<Long>>> rangeWithHistory = keyValueService.getRangeOfTimestamps(TEST_TABLE, range, TEST_TIMESTAMP + 2);
RowResult<Set<Long>> row = rangeWithHistory.next();
assertFalse(rangeWithHistory.hasNext());
rangeWithHistory.close();
assertEquals(1, Iterables.size(row.getCells()));
Entry<Cell, Set<Long>> cell0 = row.getCells().iterator().next();
assertEquals(2, cell0.getValue().size());
assertTrue(cell0.getValue().contains(TEST_TIMESTAMP));
assertTrue(cell0.getValue().contains(TEST_TIMESTAMP + 1));
}
use of com.palantir.atlasdb.keyvalue.api.RangeRequest in project atlasdb by palantir.
the class AbstractKeyValueServiceTest method doTestGetRangePaging.
private void doTestGetRangePaging(int numColumnsInMetadata, int batchSizeHint, boolean reverse) {
TableReference tableRef = createTableWithNamedColumns(numColumnsInMetadata);
Map<Cell, byte[]> values = new HashMap<Cell, byte[]>();
values.put(Cell.create(PtBytes.toBytes("00"), PtBytes.toBytes("c1")), PtBytes.toBytes("a"));
values.put(Cell.create(PtBytes.toBytes("00"), PtBytes.toBytes("c2")), PtBytes.toBytes("b"));
values.put(Cell.create(PtBytes.toBytes("01"), RangeRequests.getFirstRowName()), PtBytes.toBytes("c"));
values.put(Cell.create(PtBytes.toBytes("02"), PtBytes.toBytes("c1")), PtBytes.toBytes("d"));
values.put(Cell.create(PtBytes.toBytes("02"), PtBytes.toBytes("c2")), PtBytes.toBytes("e"));
values.put(Cell.create(PtBytes.toBytes("03"), PtBytes.toBytes("c1")), PtBytes.toBytes("f"));
values.put(Cell.create(PtBytes.toBytes("04"), PtBytes.toBytes("c1")), PtBytes.toBytes("g"));
values.put(Cell.create(PtBytes.toBytes("04"), RangeRequests.getLastRowName()), PtBytes.toBytes("h"));
values.put(Cell.create(PtBytes.toBytes("05"), PtBytes.toBytes("c1")), PtBytes.toBytes("i"));
values.put(Cell.create(RangeRequests.getLastRowName(), PtBytes.toBytes("c1")), PtBytes.toBytes("j"));
keyValueService.put(tableRef, values, TEST_TIMESTAMP);
RangeRequest request = RangeRequest.builder(reverse).batchHint(batchSizeHint).build();
try (ClosableIterator<RowResult<Value>> iter = keyValueService.getRange(tableRef, request, Long.MAX_VALUE)) {
List<RowResult<Value>> results = ImmutableList.copyOf(iter);
List<RowResult<Value>> expected = ImmutableList.of(RowResult.create(PtBytes.toBytes("00"), ImmutableSortedMap.<byte[], Value>orderedBy(UnsignedBytes.lexicographicalComparator()).put(PtBytes.toBytes("c1"), Value.create(PtBytes.toBytes("a"), TEST_TIMESTAMP)).put(PtBytes.toBytes("c2"), Value.create(PtBytes.toBytes("b"), TEST_TIMESTAMP)).build()), RowResult.create(PtBytes.toBytes("01"), ImmutableSortedMap.<byte[], Value>orderedBy(UnsignedBytes.lexicographicalComparator()).put(RangeRequests.getFirstRowName(), Value.create(PtBytes.toBytes("c"), TEST_TIMESTAMP)).build()), RowResult.create(PtBytes.toBytes("02"), ImmutableSortedMap.<byte[], Value>orderedBy(UnsignedBytes.lexicographicalComparator()).put(PtBytes.toBytes("c1"), Value.create(PtBytes.toBytes("d"), TEST_TIMESTAMP)).put(PtBytes.toBytes("c2"), Value.create(PtBytes.toBytes("e"), TEST_TIMESTAMP)).build()), RowResult.create(PtBytes.toBytes("03"), ImmutableSortedMap.<byte[], Value>orderedBy(UnsignedBytes.lexicographicalComparator()).put(PtBytes.toBytes("c1"), Value.create(PtBytes.toBytes("f"), TEST_TIMESTAMP)).build()), RowResult.create(PtBytes.toBytes("04"), ImmutableSortedMap.<byte[], Value>orderedBy(UnsignedBytes.lexicographicalComparator()).put(PtBytes.toBytes("c1"), Value.create(PtBytes.toBytes("g"), TEST_TIMESTAMP)).put(RangeRequests.getLastRowName(), Value.create(PtBytes.toBytes("h"), TEST_TIMESTAMP)).build()), RowResult.create(PtBytes.toBytes("05"), ImmutableSortedMap.<byte[], Value>orderedBy(UnsignedBytes.lexicographicalComparator()).put(PtBytes.toBytes("c1"), Value.create(PtBytes.toBytes("i"), TEST_TIMESTAMP)).build()), RowResult.create(RangeRequests.getLastRowName(), ImmutableSortedMap.<byte[], Value>orderedBy(UnsignedBytes.lexicographicalComparator()).put(PtBytes.toBytes("c1"), Value.create(PtBytes.toBytes("j"), TEST_TIMESTAMP)).build()));
assertEquals(reverse ? Lists.reverse(expected) : expected, results);
}
}
use of com.palantir.atlasdb.keyvalue.api.RangeRequest in project atlasdb by palantir.
the class AtlasDbServiceImpl method getRange.
@Override
public RangeToken getRange(TransactionToken token, final TableRange range) {
return runReadOnly(token, transaction -> {
int limit = range.getBatchSize() + 1;
RangeRequest request = RangeRequest.builder().startRowInclusive(range.getStartRow()).endRowExclusive(range.getEndRow()).batchHint(limit).retainColumns(range.getColumns()).build();
BatchingVisitable<RowResult<byte[]>> visitable = transaction.getRange(getTableRef(range.getTableName()), request);
List<RowResult<byte[]>> results = BatchingVisitables.limit(visitable, limit).immutableCopy();
if (results.size() == limit) {
TableRowResult data = new TableRowResult(range.getTableName(), results.subList(0, limit - 1));
RowResult<byte[]> lastResultInBatch = results.get(limit - 1);
TableRange nextRange = range.withStartRow(lastResultInBatch.getRowName());
return new RangeToken(data, nextRange);
} else {
TableRowResult data = new TableRowResult(range.getTableName(), results);
return new RangeToken(data, null);
}
});
}
use of com.palantir.atlasdb.keyvalue.api.RangeRequest in project atlasdb by palantir.
the class TransactionGetBenchmarks method getSingleRowWithRangeQueryInner.
private List<RowResult<byte[]>> getSingleRowWithRangeQueryInner(final ConsecutiveNarrowTable table) {
return table.getTransactionManager().runTaskThrowOnConflict(txn -> {
RangeRequest request = Iterables.getOnlyElement(table.getRangeRequests(1, 1, false));
List<RowResult<byte[]>> result = BatchingVisitables.copyToList(txn.getRange(table.getTableRef(), request));
byte[] rowName = Iterables.getOnlyElement(result).getRowName();
int rowNumber = ConsecutiveNarrowTable.rowNumber(rowName);
int expectedRowNumber = ConsecutiveNarrowTable.rowNumber(request.getStartInclusive());
Preconditions.checkState(rowNumber == expectedRowNumber, "Start Row %s, row number %s", expectedRowNumber, rowNumber);
return result;
});
}
Aggregations