Search in sources :

Example 6 with StringValue

use of com.palantir.atlasdb.table.description.test.StringValue 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;
}
Also used : ColumnSelection(com.palantir.atlasdb.keyvalue.api.ColumnSelection) String(java.lang.String) StringValue(com.palantir.atlasdb.table.description.test.StringValue) LinkedHashMap(java.util.LinkedHashMap)

Example 7 with StringValue

use of com.palantir.atlasdb.table.description.test.StringValue 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;
}
Also used : ColumnSelection(com.palantir.atlasdb.keyvalue.api.ColumnSelection) String(java.lang.String) StringValue(com.palantir.atlasdb.table.description.test.StringValue) LinkedHashMap(java.util.LinkedHashMap)

Aggregations

StringValue (com.palantir.atlasdb.table.description.test.StringValue)7 ColumnSelection (com.palantir.atlasdb.keyvalue.api.ColumnSelection)5 RangeRequest (com.palantir.atlasdb.keyvalue.api.RangeRequest)5 Test (org.junit.Test)4 PtBytes (com.palantir.atlasdb.encoding.PtBytes)3 Cell (com.palantir.atlasdb.keyvalue.api.Cell)3 Transaction (com.palantir.atlasdb.transaction.api.Transaction)3 BatchingVisitableView (com.palantir.common.base.BatchingVisitableView)3 String (java.lang.String)3 LinkedHashMap (java.util.LinkedHashMap)3 List (java.util.List)3 Map (java.util.Map)3 Optional (java.util.Optional)3 Collectors (java.util.stream.Collectors)3 Hashing (com.google.common.hash.Hashing)2 EncodingUtils (com.palantir.atlasdb.ptobject.EncodingUtils)2 ApiTestTableFactory (com.palantir.atlasdb.table.description.generated.ApiTestTableFactory)2 HashComponentsTestTable (com.palantir.atlasdb.table.description.generated.HashComponentsTestTable)2 SchemaApiTestTable (com.palantir.atlasdb.table.description.generated.SchemaApiTestTable)2 SchemaApiTestRow (com.palantir.atlasdb.table.description.generated.SchemaApiTestTable.SchemaApiTestRow)2