use of com.palantir.atlasdb.keyvalue.api.ColumnSelection in project atlasdb by palantir.
the class SchemaApiTestV2Table method getSmallRowRangeColumn1.
/**
* Returns a mapping from the first sizeLimit row keys in a rangeRequest to their value
* at column Column1 (if that column exists). As the Column1 entries are all loaded in memory,
* do not use for large values of sizeLimit. The order of results is preserved in the map.
*/
public LinkedHashMap<String, Long> getSmallRowRangeColumn1(RangeRequest rangeRequest, int sizeLimit) {
ColumnSelection colSelection = ColumnSelection.create(ImmutableList.of(PtBytes.toCachedBytes("c")));
rangeRequest = rangeRequest.getBuilder().retainColumns(colSelection).batchHint(sizeLimit).build();
Preconditions.checkArgument(rangeRequest.getColumnNames().size() <= 1, "Must not request columns other than Column1.");
LinkedHashMap<String, Long> resultsMap = new LinkedHashMap<>();
BatchingVisitableView.of(t.getRange(tableRef, rangeRequest)).batchAccept(sizeLimit, batch -> {
batch.forEach(entry -> {
SchemaApiTestTable.SchemaApiTestRowResult resultEntry = SchemaApiTestTable.SchemaApiTestRowResult.of(entry);
resultsMap.put(resultEntry.getRowName().getComponent1(), resultEntry.getColumn1());
});
// stops the traversal after the first batch
return false;
});
return resultsMap;
}
use of com.palantir.atlasdb.keyvalue.api.ColumnSelection in project atlasdb by palantir.
the class SchemaApiTestV2Table method getColumn1.
/**
* Returns a mapping from the specified row keys to their value at column Column1.
* As the Column1 values are all loaded in memory, do not use for large amounts of data.
* If the column does not exist for a key, the entry will be omitted from the map.
*/
public Map<String, Long> getColumn1(Iterable<String> rowKeys) {
ColumnSelection colSelection = ColumnSelection.create(ImmutableList.of(PtBytes.toCachedBytes("c")));
List<SchemaApiTestTable.SchemaApiTestRow> rows = Lists.newArrayList(rowKeys).stream().map(SchemaApiTestTable.SchemaApiTestRow::of).collect(Collectors.toList());
SortedMap<byte[], RowResult<byte[]>> results = t.getRows(tableRef, Persistables.persistAll(rows), colSelection);
return results.values().stream().map(entry -> SchemaApiTestTable.SchemaApiTestRowResult.of(entry)).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 SchemaApiTestImpl method getRangeSecondColumnOnlyFirstTwoResults.
@Override
protected Map<String, StringValue> getRangeSecondColumnOnlyFirstTwoResults(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).batchHint(2).build();
BatchingVisitableView<SchemaApiTestRowResult> rangeRequestResult = table.getRange(rangeRequest);
return BatchingVisitables.take(rangeRequestResult, 2).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 SerializableTransaction method verifyRows.
private void verifyRows(Transaction ro) {
for (Map.Entry<TableReference, Set<RowRead>> tableAndRowsEntry : rowsRead.entrySet()) {
TableReference table = tableAndRowsEntry.getKey();
Set<RowRead> rows = tableAndRowsEntry.getValue();
ConcurrentNavigableMap<Cell, byte[]> readsForTable = getReadsForTable(table);
Multimap<ColumnSelection, byte[]> rowsReadByColumns = Multimaps.newSortedSetMultimap(Maps.newHashMap(), () -> Sets.newTreeSet(UnsignedBytes.lexicographicalComparator()));
for (RowRead r : rows) {
rowsReadByColumns.putAll(r.cols, r.rows);
}
for (ColumnSelection cols : rowsReadByColumns.keySet()) {
verifyColumns(ro, table, readsForTable, rowsReadByColumns, cols);
}
}
}
use of com.palantir.atlasdb.keyvalue.api.ColumnSelection in project atlasdb by palantir.
the class SchemaApiTestImpl method getSingleRowFirstColumn.
@Override
protected Long getSingleRowFirstColumn(Transaction transaction, String rowKey) {
SchemaApiTestTable table = tableFactory.getSchemaApiTestTable(transaction);
ColumnSelection firstColSelection = SchemaApiTestTable.getColumnSelection(SchemaApiTestTable.SchemaApiTestNamedColumn.COLUMN1);
Optional<SchemaApiTestRowResult> result = table.getRow(SchemaApiTestRow.of(rowKey), firstColSelection);
return result.get().getColumn1();
}
Aggregations