use of com.palantir.util.paging.TokenBackedBasicResultsPage in project atlasdb by palantir.
the class DbKvs method getTimestampsPageInternal.
private TokenBackedBasicResultsPage<RowResult<Set<Long>>, Token> getTimestampsPageInternal(DbReadTable table, RangeRequest range, long timestamp, long batchSize, Token token) {
Set<byte[]> rows = Sets.newHashSet();
int maxRows = getMaxRowsFromBatchHint(range.getBatchHint());
try (ClosableIterator<AgnosticLightResultRow> rangeResults = table.getRange(range, timestamp, maxRows)) {
while (rows.size() < maxRows && rangeResults.hasNext()) {
byte[] rowName = rangeResults.next().getBytes(ROW);
if (rowName != null) {
rows.add(rowName);
}
}
if (rows.isEmpty()) {
return SimpleTokenBackedResultsPage.create(null, ImmutableList.<RowResult<Set<Long>>>of(), false);
}
}
ColumnSelection cols = range.getColumnNames().isEmpty() ? ColumnSelection.all() : ColumnSelection.create(range.getColumnNames());
TimestampsByCellResultWithToken result = getTimestampsByCell(table, rows, cols, timestamp, batchSize, range.isReverse(), token);
NavigableMap<byte[], SortedMap<byte[], Set<Long>>> cellsByRow = Cells.breakCellsUpByRow(Multimaps.asMap(result.entries));
if (range.isReverse()) {
cellsByRow = cellsByRow.descendingMap();
}
List<RowResult<Set<Long>>> finalResults = cellsByRow.entrySet().stream().map(entry -> RowResult.create(entry.getKey(), entry.getValue())).collect(Collectors.toList());
return SimpleTokenBackedResultsPage.create(result.getToken(), finalResults, result.mayHaveMoreResults());
}
use of com.palantir.util.paging.TokenBackedBasicResultsPage 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.util.paging.TokenBackedBasicResultsPage in project atlasdb by palantir.
the class AbstractTransactionTest method testRangeAfterTimestamp2.
@Test
public void testRangeAfterTimestamp2() {
putDirect("row1", "col2", "", 5);
putDirect("row2", "col2", "", 0);
putDirect("row3", "col2", "", 0);
RangeRequest rangeRequest = RangeRequest.builder().batchHint(1).build();
Map<RangeRequest, TokenBackedBasicResultsPage<RowResult<Value>, byte[]>> ranges = keyValueService.getFirstBatchForRanges(TEST_TABLE, Collections.singleton(rangeRequest), 1);
assertEquals(1, ranges.keySet().size());
TokenBackedBasicResultsPage<RowResult<Value>, byte[]> page = ranges.values().iterator().next();
assertTrue(page.moreResultsAvailable());
}
use of com.palantir.util.paging.TokenBackedBasicResultsPage in project atlasdb by palantir.
the class AbstractTransactionTest method testRangeAfterTimestamp.
@Test
public void testRangeAfterTimestamp() {
putDirect("row1", "col2", "", 5);
putDirect("row2", "col2", "", 0);
RangeRequest rangeRequest = RangeRequest.builder().batchHint(1).build();
Map<RangeRequest, TokenBackedBasicResultsPage<RowResult<Value>, byte[]>> ranges = keyValueService.getFirstBatchForRanges(TEST_TABLE, Collections.singleton(rangeRequest), 1);
assertEquals(1, ranges.keySet().size());
TokenBackedBasicResultsPage<RowResult<Value>, byte[]> page = ranges.values().iterator().next();
assertTrue(!page.getResults().isEmpty() || page.moreResultsAvailable());
}
use of com.palantir.util.paging.TokenBackedBasicResultsPage in project atlasdb by palantir.
the class AbstractTransactionTest method testRangePageBatchSizeOne.
@Test
public void testRangePageBatchSizeOne() {
RangeRequest rangeRequest = RangeRequest.builder().batchHint(1).build();
Map<RangeRequest, TokenBackedBasicResultsPage<RowResult<Value>, byte[]>> ranges = keyValueService.getFirstBatchForRanges(TEST_TABLE, Collections.singleton(rangeRequest), 1);
assertEquals(1, ranges.keySet().size());
assertEquals(0, ranges.values().iterator().next().getResults().size());
assertEquals(false, ranges.values().iterator().next().moreResultsAvailable());
}
Aggregations