use of com.palantir.atlasdb.keyvalue.api.RowColumnRangeIterator in project atlasdb by palantir.
the class DbKvs method getRowsColumnRange.
@Override
public Map<byte[], RowColumnRangeIterator> getRowsColumnRange(TableReference tableRef, Iterable<byte[]> rows, BatchColumnRangeSelection batchColumnRangeSelection, long timestamp) {
List<byte[]> rowList = ImmutableList.copyOf(rows);
Map<byte[], List<Map.Entry<Cell, Value>>> firstPage = getFirstRowsColumnRangePage(tableRef, rowList, batchColumnRangeSelection, timestamp);
Map<byte[], RowColumnRangeIterator> ret = Maps.newHashMapWithExpectedSize(rowList.size());
for (Entry<byte[], List<Map.Entry<Cell, Value>>> e : firstPage.entrySet()) {
List<Map.Entry<Cell, Value>> results = e.getValue();
if (results.isEmpty()) {
ret.put(e.getKey(), new LocalRowColumnRangeIterator(e.getValue().iterator()));
continue;
}
byte[] lastCol = results.get(results.size() - 1).getKey().getColumnName();
RowColumnRangeIterator firstPageIter = new LocalRowColumnRangeIterator(e.getValue().iterator());
if (isEndOfColumnRange(lastCol, batchColumnRangeSelection.getEndCol())) {
ret.put(e.getKey(), firstPageIter);
} else {
byte[] nextCol = RangeRequests.nextLexicographicName(lastCol);
BatchColumnRangeSelection nextColumnRangeSelection = BatchColumnRangeSelection.create(nextCol, batchColumnRangeSelection.getEndCol(), batchColumnRangeSelection.getBatchHint());
Iterator<Map.Entry<Cell, Value>> nextPagesIter = getRowColumnRange(tableRef, e.getKey(), nextColumnRangeSelection, timestamp);
ret.put(e.getKey(), new LocalRowColumnRangeIterator(Iterators.concat(firstPageIter, nextPagesIter)));
}
}
return ret;
}
use of com.palantir.atlasdb.keyvalue.api.RowColumnRangeIterator in project atlasdb by palantir.
the class AbstractKeyValueServiceTest method testGetRowColumnRangeCellBatchHistorical.
@Test
public void testGetRowColumnRangeCellBatchHistorical() {
putTestDataForMultipleTimestamps();
RowColumnRangeIterator values = keyValueService.getRowsColumnRange(TEST_TABLE, ImmutableList.of(row0), new ColumnRangeSelection(PtBytes.EMPTY_BYTE_ARRAY, PtBytes.EMPTY_BYTE_ARRAY), 1, TEST_TIMESTAMP + 2);
assertNextElementMatches(values, TEST_CELL, value0_t1);
assertFalse(values.hasNext());
values = keyValueService.getRowsColumnRange(TEST_TABLE, ImmutableList.of(row0), new ColumnRangeSelection(PtBytes.EMPTY_BYTE_ARRAY, PtBytes.EMPTY_BYTE_ARRAY), 1, TEST_TIMESTAMP + 1);
assertNextElementMatches(values, TEST_CELL, value0_t0);
assertFalse(values.hasNext());
}
use of com.palantir.atlasdb.keyvalue.api.RowColumnRangeIterator in project atlasdb by palantir.
the class AbstractKeyValueServiceTest method testGetRowColumnRangeCellBatchSingleRow.
@Test
public void testGetRowColumnRangeCellBatchSingleRow() {
putTestDataForSingleTimestamp();
RowColumnRangeIterator values = keyValueService.getRowsColumnRange(TEST_TABLE, ImmutableList.of(row1), new ColumnRangeSelection(PtBytes.EMPTY_BYTE_ARRAY, PtBytes.EMPTY_BYTE_ARRAY), 1, TEST_TIMESTAMP + 1);
assertNextElementMatches(values, Cell.create(row1, column0), value10);
assertNextElementMatches(values, Cell.create(row1, column2), value12);
assertFalse(values.hasNext());
values = keyValueService.getRowsColumnRange(TEST_TABLE, ImmutableList.of(row1), new ColumnRangeSelection(RangeRequests.nextLexicographicName(column0), PtBytes.EMPTY_BYTE_ARRAY), 1, TEST_TIMESTAMP + 1);
assertNextElementMatches(values, Cell.create(row1, column2), value12);
assertFalse(values.hasNext());
values = keyValueService.getRowsColumnRange(TEST_TABLE, ImmutableList.of(row1), new ColumnRangeSelection(RangeRequests.nextLexicographicName(column0), column2), 1, TEST_TIMESTAMP + 1);
assertFalse(values.hasNext());
values = keyValueService.getRowsColumnRange(TEST_TABLE, ImmutableList.of(row1), new ColumnRangeSelection(RangeRequests.nextLexicographicName(column2), PtBytes.EMPTY_BYTE_ARRAY), 1, TEST_TIMESTAMP + 1);
assertFalse(values.hasNext());
values = keyValueService.getRowsColumnRange(TEST_TABLE, ImmutableList.of(row1), new ColumnRangeSelection(PtBytes.EMPTY_BYTE_ARRAY, PtBytes.EMPTY_BYTE_ARRAY), Integer.MAX_VALUE, TEST_TIMESTAMP + 1);
assertNextElementMatches(values, Cell.create(row1, column0), value10);
assertNextElementMatches(values, Cell.create(row1, column2), value12);
assertFalse(values.hasNext());
}
use of com.palantir.atlasdb.keyvalue.api.RowColumnRangeIterator in project atlasdb by palantir.
the class AbstractKeyValueServiceTest method testGetRowColumnRangeCellBatchMultipleHistorical.
@Test
public void testGetRowColumnRangeCellBatchMultipleHistorical() {
keyValueService.put(TEST_TABLE, ImmutableMap.of(Cell.create(row1, column0), value0_t0), TEST_TIMESTAMP);
keyValueService.put(TEST_TABLE, ImmutableMap.of(Cell.create(row1, column0), value0_t1), TEST_TIMESTAMP + 1);
keyValueService.put(TEST_TABLE, ImmutableMap.of(Cell.create(row1, column1), value0_t0), TEST_TIMESTAMP);
keyValueService.put(TEST_TABLE, ImmutableMap.of(Cell.create(row1, column1), value0_t1), TEST_TIMESTAMP + 1);
RowColumnRangeIterator values = keyValueService.getRowsColumnRange(TEST_TABLE, ImmutableList.of(row1), new ColumnRangeSelection(PtBytes.EMPTY_BYTE_ARRAY, RangeRequests.nextLexicographicName(column1)), 2, TEST_TIMESTAMP + 1);
assertNextElementMatches(values, Cell.create(row1, column0), value0_t0);
assertNextElementMatches(values, Cell.create(row1, column1), value0_t0);
assertFalse(values.hasNext());
}
use of com.palantir.atlasdb.keyvalue.api.RowColumnRangeIterator in project atlasdb by palantir.
the class KeyValueServices method mergeGetRowsColumnRangeIntoSingleIterator.
public static RowColumnRangeIterator mergeGetRowsColumnRangeIntoSingleIterator(KeyValueService kvs, TableReference tableRef, Iterable<byte[]> rows, ColumnRangeSelection columnRangeSelection, int batchHint, long timestamp) {
if (Iterables.isEmpty(rows)) {
return new LocalRowColumnRangeIterator(Collections.emptyIterator());
}
int columnBatchSize = batchHint / Iterables.size(rows);
BatchColumnRangeSelection batchColumnRangeSelection = BatchColumnRangeSelection.create(columnRangeSelection, columnBatchSize);
Map<byte[], RowColumnRangeIterator> rowsColumnRanges = kvs.getRowsColumnRange(tableRef, rows, batchColumnRangeSelection, timestamp);
// Return results in the same order as the provided rows.
Iterable<RowColumnRangeIterator> orderedRanges = Iterables.transform(rows, rowsColumnRanges::get);
return new LocalRowColumnRangeIterator(Iterators.concat(orderedRanges.iterator()));
}
Aggregations