use of com.palantir.atlasdb.keyvalue.api.ColumnSelection in project atlasdb by palantir.
the class SchemaApiTestV2Table method getSmallRowRangeColumn2.
/**
* Returns a mapping from all the row keys in a rangeRequest to their value at column Column2
* (if that column exists for the row-key). As the Column2 values are all loaded in memory,
* do not use for large amounts of data. The order of results is preserved in the map.
*/
public LinkedHashMap<String, StringValue> getSmallRowRangeColumn2(RangeRequest rangeRequest) {
ColumnSelection colSelection = ColumnSelection.create(ImmutableList.of(PtBytes.toCachedBytes("d")));
rangeRequest = rangeRequest.getBuilder().retainColumns(colSelection).build();
Preconditions.checkArgument(rangeRequest.getColumnNames().size() <= 1, "Must not request columns other than Column2.");
LinkedHashMap<String, StringValue> resultsMap = new LinkedHashMap<>();
BatchingVisitableView.of(t.getRange(tableRef, rangeRequest)).immutableCopy().forEach(entry -> {
SchemaApiTestTable.SchemaApiTestRowResult resultEntry = SchemaApiTestTable.SchemaApiTestRowResult.of(entry);
resultsMap.put(resultEntry.getRowName().getComponent1(), resultEntry.getColumn2());
});
return resultsMap;
}
use of com.palantir.atlasdb.keyvalue.api.ColumnSelection in project atlasdb by palantir.
the class SchemaApiTestV2Table method getColumn1.
/**
* Returns the value for column Column1 and specified row components.
*/
public Optional<Long> getColumn1(String component1) {
SchemaApiTestTable.SchemaApiTestRow row = SchemaApiTestTable.SchemaApiTestRow.of(component1);
byte[] bytes = row.persistToBytes();
ColumnSelection colSelection = ColumnSelection.create(ImmutableList.of(PtBytes.toCachedBytes("c")));
RowResult<byte[]> rowResult = t.getRows(tableRef, ImmutableSet.of(bytes), colSelection).get(bytes);
if (rowResult == null) {
return Optional.empty();
} else {
return Optional.of(SchemaApiTestTable.SchemaApiTestRowResult.of(rowResult).getColumn1());
}
}
use of com.palantir.atlasdb.keyvalue.api.ColumnSelection in project atlasdb by palantir.
the class SchemaApiTestV2Table method getColumn2.
/**
* Returns the value for column Column2 and specified row components.
*/
public Optional<StringValue> getColumn2(String component1) {
SchemaApiTestTable.SchemaApiTestRow row = SchemaApiTestTable.SchemaApiTestRow.of(component1);
byte[] bytes = row.persistToBytes();
ColumnSelection colSelection = ColumnSelection.create(ImmutableList.of(PtBytes.toCachedBytes("d")));
RowResult<byte[]> rowResult = t.getRows(tableRef, ImmutableSet.of(bytes), colSelection).get(bytes);
if (rowResult == null) {
return Optional.empty();
} else {
return Optional.of(SchemaApiTestTable.SchemaApiTestRowResult.of(rowResult).getColumn2());
}
}
use of com.palantir.atlasdb.keyvalue.api.ColumnSelection in project atlasdb by palantir.
the class SchemaApiTestV2Table method getSmallRowRangeColumn2.
/**
* Returns a mapping from the first sizeLimit row keys in a rangeRequest to their value
* at column Column2 (if that column exists). As the Column2 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, StringValue> getSmallRowRangeColumn2(RangeRequest rangeRequest, int sizeLimit) {
ColumnSelection colSelection = ColumnSelection.create(ImmutableList.of(PtBytes.toCachedBytes("d")));
rangeRequest = rangeRequest.getBuilder().retainColumns(colSelection).batchHint(sizeLimit).build();
Preconditions.checkArgument(rangeRequest.getColumnNames().size() <= 1, "Must not request columns other than Column2.");
LinkedHashMap<String, StringValue> 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.getColumn2());
});
// stops the traversal after the first batch
return false;
});
return resultsMap;
}
Aggregations