use of com.palantir.atlasdb.keyvalue.api.RowResult in project atlasdb by palantir.
the class KvsGetRangeBenchmarks method getSingleRangeInner.
private Object getSingleRangeInner(ConsecutiveNarrowTable table, int sliceSize) {
RangeRequest request = Iterables.getOnlyElement(table.getRangeRequests(1, sliceSize, false));
int startRow = Ints.fromByteArray(request.getStartInclusive());
ClosableIterator<RowResult<Value>> result = table.getKvs().getRange(table.getTableRef(), request, Long.MAX_VALUE);
ArrayList<RowResult<Value>> list = Lists.newArrayList(result);
result.close();
Preconditions.checkState(list.size() == sliceSize, "List size %s != %s", sliceSize, list.size());
list.forEach(rowResult -> {
byte[] rowName = rowResult.getRowName();
int rowNumber = Ints.fromByteArray(rowName);
Preconditions.checkState(rowNumber - startRow < sliceSize, "Start Row %s, row number %s, sliceSize %s", startRow, rowNumber, sliceSize);
});
return result;
}
use of com.palantir.atlasdb.keyvalue.api.RowResult in project atlasdb by palantir.
the class JdbcKeyValueService method getRangeOfTimestamps.
@Override
public ClosableIterator<RowResult<Set<Long>>> getRangeOfTimestamps(final TableReference tableRef, final RangeRequest rangeRequest, final long timestamp) {
Iterable<RowResult<Set<Long>>> iter = new AbstractPagingIterable<RowResult<Set<Long>>, TokenBackedBasicResultsPage<RowResult<Set<Long>>, byte[]>>() {
@Override
protected TokenBackedBasicResultsPage<RowResult<Set<Long>>, byte[]> getFirstPage() {
return getPageWithTimestamps(tableRef, rangeRequest, timestamp);
}
@Override
protected TokenBackedBasicResultsPage<RowResult<Set<Long>>, byte[]> getNextPage(TokenBackedBasicResultsPage<RowResult<Set<Long>>, byte[]> previous) {
byte[] startRow = previous.getTokenForNextPage();
RangeRequest newRange = rangeRequest.getBuilder().startRowInclusive(startRow).build();
return getPageWithTimestamps(tableRef, newRange, timestamp);
}
};
return ClosableIterators.wrap(iter.iterator());
}
use of com.palantir.atlasdb.keyvalue.api.RowResult in project atlasdb by palantir.
the class AbstractKeyValueServiceTest method testGetRange.
public void testGetRange(boolean reverseSupported) {
putTestDataForSingleTimestamp();
// Unbounded
final RangeRequest all = RangeRequest.all();
assertRangeSizeAndOrdering(keyValueService.getRange(TEST_TABLE, all, TEST_TIMESTAMP + 1), 3, all);
if (reverseSupported) {
final RangeRequest allReverse = RangeRequest.reverseBuilder().build();
assertRangeSizeAndOrdering(keyValueService.getRange(TEST_TABLE, allReverse, TEST_TIMESTAMP + 1), 3, allReverse);
}
// Upbounded
final RangeRequest upbounded = RangeRequest.builder().endRowExclusive(row2).build();
assertRangeSizeAndOrdering(keyValueService.getRange(TEST_TABLE, upbounded, TEST_TIMESTAMP + 1), 2, upbounded);
if (reverseSupported) {
final RangeRequest upboundedReverse = RangeRequest.reverseBuilder().endRowExclusive(row0).build();
assertRangeSizeAndOrdering(keyValueService.getRange(TEST_TABLE, upboundedReverse, TEST_TIMESTAMP + 1), 2, upboundedReverse);
}
// Downbounded
final RangeRequest downbounded = RangeRequest.builder().startRowInclusive(row1).build();
assertRangeSizeAndOrdering(keyValueService.getRange(TEST_TABLE, downbounded, TEST_TIMESTAMP + 1), 2, downbounded);
if (reverseSupported) {
final RangeRequest downboundedReverse = RangeRequest.reverseBuilder().startRowInclusive(row1).build();
assertRangeSizeAndOrdering(keyValueService.getRange(TEST_TABLE, downboundedReverse, TEST_TIMESTAMP + 1), 2, downboundedReverse);
}
// Both-bounded
final RangeRequest bothbounded = RangeRequest.builder().startRowInclusive(row1).endRowExclusive(row2).build();
assertRangeSizeAndOrdering(keyValueService.getRange(TEST_TABLE, bothbounded, TEST_TIMESTAMP + 1), 1, bothbounded);
if (reverseSupported) {
final RangeRequest bothboundedReverse = RangeRequest.reverseBuilder().startRowInclusive(row2).endRowExclusive(row1).build();
assertRangeSizeAndOrdering(keyValueService.getRange(TEST_TABLE, bothboundedReverse, TEST_TIMESTAMP + 1), 1, bothboundedReverse);
}
// Precise test for lower-bounded
RangeRequest rangeRequest = downbounded;
ClosableIterator<RowResult<Value>> rangeResult = keyValueService.getRange(TEST_TABLE, rangeRequest, TEST_TIMESTAMP + 1);
assertFalse(keyValueService.getRange(TEST_TABLE, rangeRequest, TEST_TIMESTAMP).hasNext());
assertTrue(rangeResult.hasNext());
assertEquals(RowResult.create(row1, ImmutableSortedMap.orderedBy(UnsignedBytes.lexicographicalComparator()).put(column0, Value.create(value10, TEST_TIMESTAMP)).put(column2, Value.create(value12, TEST_TIMESTAMP)).build()), rangeResult.next());
assertTrue(rangeResult.hasNext());
assertEquals(RowResult.create(row2, ImmutableSortedMap.orderedBy(UnsignedBytes.lexicographicalComparator()).put(column1, Value.create(value21, TEST_TIMESTAMP)).put(column2, Value.create(value22, TEST_TIMESTAMP)).build()), rangeResult.next());
rangeResult.close();
}
use of com.palantir.atlasdb.keyvalue.api.RowResult 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.RowResult 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));
}
Aggregations