Search in sources :

Example 16 with ColumnSelection

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;
}
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 17 with ColumnSelection

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());
    }
}
Also used : ColumnSelection(com.palantir.atlasdb.keyvalue.api.ColumnSelection)

Example 18 with ColumnSelection

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());
    }
}
Also used : ColumnSelection(com.palantir.atlasdb.keyvalue.api.ColumnSelection)

Example 19 with ColumnSelection

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;
}
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

ColumnSelection (com.palantir.atlasdb.keyvalue.api.ColumnSelection)19 StringValue (com.palantir.atlasdb.table.description.test.StringValue)7 LinkedHashMap (java.util.LinkedHashMap)7 Map (java.util.Map)7 Test (org.junit.Test)7 Cell (com.palantir.atlasdb.keyvalue.api.Cell)6 RangeRequest (com.palantir.atlasdb.keyvalue.api.RangeRequest)6 Transaction (com.palantir.atlasdb.transaction.api.Transaction)6 String (java.lang.String)6 List (java.util.List)6 Optional (java.util.Optional)6 Collectors (java.util.stream.Collectors)6 PtBytes (com.palantir.atlasdb.encoding.PtBytes)5 RowResult (com.palantir.atlasdb.keyvalue.api.RowResult)5 BatchingVisitableView (com.palantir.common.base.BatchingVisitableView)5 Long (java.lang.Long)4 SortedMap (java.util.SortedMap)4 Preconditions (com.google.common.base.Preconditions)3 ImmutableList (com.google.common.collect.ImmutableList)3 ImmutableSet (com.google.common.collect.ImmutableSet)3