use of com.palantir.atlasdb.keyvalue.api.ColumnSelection in project atlasdb by palantir.
the class SchemaApiTestImpl method getRangeSecondColumn.
@Override
protected Map<String, StringValue> getRangeSecondColumn(Transaction transaction, String startRowKey, String endRowKey) {
SchemaApiTestTable table = tableFactory.getSchemaApiTestTable(transaction);
ColumnSelection secondColSelection = SchemaApiTestTable.getColumnSelection(SchemaApiTestTable.SchemaApiTestNamedColumn.COLUMN2);
RangeRequest rangeRequest = RangeRequest.builder().startRowInclusive(SchemaApiTestRow.of(startRowKey).persistToBytes()).endRowExclusive(SchemaApiTestRow.of(endRowKey).persistToBytes()).retainColumns(secondColSelection).build();
BatchingVisitableView<SchemaApiTestRowResult> rangeRequestResult = table.getRange(rangeRequest);
return rangeRequestResult.immutableCopy().stream().collect(Collectors.toMap(entry -> entry.getRowName().getComponent1(), SchemaApiTestTable.SchemaApiTestRowResult::getColumn2));
}
use of com.palantir.atlasdb.keyvalue.api.ColumnSelection in project atlasdb by palantir.
the class SchemaApiTestImpl method getMultipleRowsFirstColumn.
@Override
protected Map<String, Long> getMultipleRowsFirstColumn(Transaction transaction, List<String> rowKeys) {
SchemaApiTestTable table = tableFactory.getSchemaApiTestTable(transaction);
ColumnSelection firstColSelection = SchemaApiTestTable.getColumnSelection(SchemaApiTestTable.SchemaApiTestNamedColumn.COLUMN1);
List<SchemaApiTestRowResult> result = table.getRows(rowKeys.stream().map(SchemaApiTestRow::of).collect(Collectors.toList()), firstColSelection);
return result.stream().collect(Collectors.toMap(entry -> entry.getRowName().getComponent1(), SchemaApiTestTable.SchemaApiTestRowResult::getColumn1));
}
use of com.palantir.atlasdb.keyvalue.api.ColumnSelection 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.atlasdb.keyvalue.api.ColumnSelection in project atlasdb by palantir.
the class AbstractKeyValueServiceTest method testGetRowsWithSelectedColumns.
@Test
public void testGetRowsWithSelectedColumns() {
putTestDataForSingleTimestamp();
ColumnSelection columns1and2 = ColumnSelection.create(Arrays.asList(column1, column2));
Map<Cell, Value> values = keyValueService.getRows(TEST_TABLE, Arrays.asList(row1, row2), columns1and2, TEST_TIMESTAMP + 1);
assertEquals(3, values.size());
assertNull(values.get(Cell.create(row1, column0)));
assertArrayEquals(value12, values.get(Cell.create(row1, column2)).getContents());
assertArrayEquals(value21, values.get(Cell.create(row2, column1)).getContents());
assertArrayEquals(value22, values.get(Cell.create(row2, column2)).getContents());
}
use of com.palantir.atlasdb.keyvalue.api.ColumnSelection in project atlasdb by palantir.
the class SnapshotTransactionTest method testGetRowsLocalWritesWithColumnSelection.
@Test
public void testGetRowsLocalWritesWithColumnSelection() {
// This test ensures getRows correctly applies columnSelection when there are local writes
byte[] row1 = PtBytes.toBytes("row1");
Cell row1Column1 = Cell.create(row1, PtBytes.toBytes("column1"));
Cell row1Column2 = Cell.create(row1, PtBytes.toBytes("column2"));
byte[] row1Column1Value = BigInteger.valueOf(1).toByteArray();
byte[] row1Column2Value = BigInteger.valueOf(2).toByteArray();
Transaction snapshotTx = serializableTxManager.createNewTransaction();
snapshotTx.put(TABLE, ImmutableMap.of(row1Column1, row1Column1Value, row1Column2, row1Column2Value));
ColumnSelection column1Selection = ColumnSelection.create(ImmutableList.of(row1Column1.getColumnName()));
// local writes still apply columnSelection
RowResult<byte[]> rowResult1 = snapshotTx.getRows(TABLE, ImmutableList.of(row1), column1Selection).get(row1);
assertThat(rowResult1.getColumns(), hasEntry(row1Column1.getColumnName(), row1Column1Value));
assertThat(rowResult1.getColumns(), not(hasEntry(row1Column2.getColumnName(), row1Column2Value)));
RowResult<byte[]> rowResult2 = snapshotTx.getRows(TABLE, ImmutableList.of(row1), ColumnSelection.all()).get(row1);
assertThat(rowResult2.getColumns(), hasEntry(row1Column1.getColumnName(), row1Column1Value));
assertThat(rowResult2.getColumns(), hasEntry(row1Column2.getColumnName(), row1Column2Value));
}
Aggregations