Search in sources :

Example 6 with ColumnSelection

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;
}
Also used : ColumnSelection(com.palantir.atlasdb.keyvalue.api.ColumnSelection) Long(java.lang.Long) String(java.lang.String) LinkedHashMap(java.util.LinkedHashMap)

Example 7 with ColumnSelection

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));
}
Also used : StringValue(com.palantir.atlasdb.table.description.test.StringValue) Persistables(com.palantir.common.persist.Persistables) Function(java.util.function.Function) PtBytes(com.palantir.atlasdb.encoding.PtBytes) Iterable(java.lang.Iterable) LinkedHashMap(java.util.LinkedHashMap) Generated(javax.annotation.Generated) Lists(com.google.common.collect.Lists) ImmutableList(com.google.common.collect.ImmutableList) ColumnValues(com.palantir.atlasdb.table.generation.ColumnValues) Long(java.lang.Long) Map(java.util.Map) TableReference(com.palantir.atlasdb.keyvalue.api.TableReference) String(java.lang.String) ImmutableMultimap(com.google.common.collect.ImmutableMultimap) ImmutableSet(com.google.common.collect.ImmutableSet) Namespace(com.palantir.atlasdb.keyvalue.api.Namespace) SuppressWarnings(java.lang.SuppressWarnings) Cell(com.palantir.atlasdb.keyvalue.api.Cell) Set(java.util.Set) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) ColumnSelection(com.palantir.atlasdb.keyvalue.api.ColumnSelection) RangeRequest(com.palantir.atlasdb.keyvalue.api.RangeRequest) RowResult(com.palantir.atlasdb.keyvalue.api.RowResult) Objects(java.util.Objects) List(java.util.List) Transaction(com.palantir.atlasdb.transaction.api.Transaction) BatchingVisitableView(com.palantir.common.base.BatchingVisitableView) Optional(java.util.Optional) Preconditions(com.google.common.base.Preconditions) SortedMap(java.util.SortedMap) ColumnSelection(com.palantir.atlasdb.keyvalue.api.ColumnSelection) RowResult(com.palantir.atlasdb.keyvalue.api.RowResult)

Example 8 with ColumnSelection

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));
}
Also used : StringValue(com.palantir.atlasdb.table.description.test.StringValue) EncodingUtils(com.palantir.atlasdb.ptobject.EncodingUtils) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) HashComponentsTestTable(com.palantir.atlasdb.table.description.generated.HashComponentsTestTable) ApiTestTableFactory(com.palantir.atlasdb.table.description.generated.ApiTestTableFactory) Test(org.junit.Test) Hashing(com.google.common.hash.Hashing) Collectors(java.util.stream.Collectors) PtBytes(com.palantir.atlasdb.encoding.PtBytes) ColumnSelection(com.palantir.atlasdb.keyvalue.api.ColumnSelection) RangeRequest(com.palantir.atlasdb.keyvalue.api.RangeRequest) SchemaApiTestRow(com.palantir.atlasdb.table.description.generated.SchemaApiTestTable.SchemaApiTestRow) List(java.util.List) Transaction(com.palantir.atlasdb.transaction.api.Transaction) Map(java.util.Map) SchemaApiTestRowResult(com.palantir.atlasdb.table.description.generated.SchemaApiTestTable.SchemaApiTestRowResult) BatchingVisitableView(com.palantir.common.base.BatchingVisitableView) Optional(java.util.Optional) SchemaApiTestTable(com.palantir.atlasdb.table.description.generated.SchemaApiTestTable) BatchingVisitables(com.palantir.common.base.BatchingVisitables) ColumnSelection(com.palantir.atlasdb.keyvalue.api.ColumnSelection) RangeRequest(com.palantir.atlasdb.keyvalue.api.RangeRequest) SchemaApiTestTable(com.palantir.atlasdb.table.description.generated.SchemaApiTestTable) SchemaApiTestRowResult(com.palantir.atlasdb.table.description.generated.SchemaApiTestTable.SchemaApiTestRowResult)

Example 9 with ColumnSelection

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);
        }
    }
}
Also used : ColumnSelection(com.palantir.atlasdb.keyvalue.api.ColumnSelection) TableReference(com.palantir.atlasdb.keyvalue.api.TableReference) ImmutableSet(com.google.common.collect.ImmutableSet) Set(java.util.Set) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) ConcurrentNavigableMap(java.util.concurrent.ConcurrentNavigableMap) NavigableMap(java.util.NavigableMap) SortedMap(java.util.SortedMap) ConcurrentMap(java.util.concurrent.ConcurrentMap) ConcurrentSkipListMap(java.util.concurrent.ConcurrentSkipListMap) Cell(com.palantir.atlasdb.keyvalue.api.Cell)

Example 10 with ColumnSelection

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

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