Search in sources :

Example 11 with ColumnSelection

use of com.palantir.atlasdb.keyvalue.api.ColumnSelection in project atlasdb by palantir.

the class SchemaApiTestImpl method getRangeSecondColumn.

@Override
protected Map<String, StringValue> getRangeSecondColumn(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).build();
    BatchingVisitableView<SchemaApiTestRowResult> rangeRequestResult = table.getRange(rangeRequest);
    return rangeRequestResult.immutableCopy().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 12 with ColumnSelection

use of com.palantir.atlasdb.keyvalue.api.ColumnSelection in project atlasdb by palantir.

the class SchemaApiTestImpl method getMultipleRowsFirstColumn.

@Override
protected Map<String, Long> getMultipleRowsFirstColumn(Transaction transaction, List<String> rowKeys) {
    SchemaApiTestTable table = tableFactory.getSchemaApiTestTable(transaction);
    ColumnSelection firstColSelection = SchemaApiTestTable.getColumnSelection(SchemaApiTestTable.SchemaApiTestNamedColumn.COLUMN1);
    List<SchemaApiTestRowResult> result = table.getRows(rowKeys.stream().map(SchemaApiTestRow::of).collect(Collectors.toList()), firstColSelection);
    return result.stream().collect(Collectors.toMap(entry -> entry.getRowName().getComponent1(), SchemaApiTestTable.SchemaApiTestRowResult::getColumn1));
}
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) SchemaApiTestRow(com.palantir.atlasdb.table.description.generated.SchemaApiTestTable.SchemaApiTestRow) SchemaApiTestTable(com.palantir.atlasdb.table.description.generated.SchemaApiTestTable) SchemaApiTestRowResult(com.palantir.atlasdb.table.description.generated.SchemaApiTestTable.SchemaApiTestRowResult)

Example 13 with ColumnSelection

use of com.palantir.atlasdb.keyvalue.api.ColumnSelection in project atlasdb by palantir.

the class DbKvs method getTimestampsPageInternal.

private TokenBackedBasicResultsPage<RowResult<Set<Long>>, Token> getTimestampsPageInternal(DbReadTable table, RangeRequest range, long timestamp, long batchSize, Token token) {
    Set<byte[]> rows = Sets.newHashSet();
    int maxRows = getMaxRowsFromBatchHint(range.getBatchHint());
    try (ClosableIterator<AgnosticLightResultRow> rangeResults = table.getRange(range, timestamp, maxRows)) {
        while (rows.size() < maxRows && rangeResults.hasNext()) {
            byte[] rowName = rangeResults.next().getBytes(ROW);
            if (rowName != null) {
                rows.add(rowName);
            }
        }
        if (rows.isEmpty()) {
            return SimpleTokenBackedResultsPage.create(null, ImmutableList.<RowResult<Set<Long>>>of(), false);
        }
    }
    ColumnSelection cols = range.getColumnNames().isEmpty() ? ColumnSelection.all() : ColumnSelection.create(range.getColumnNames());
    TimestampsByCellResultWithToken result = getTimestampsByCell(table, rows, cols, timestamp, batchSize, range.isReverse(), token);
    NavigableMap<byte[], SortedMap<byte[], Set<Long>>> cellsByRow = Cells.breakCellsUpByRow(Multimaps.asMap(result.entries));
    if (range.isReverse()) {
        cellsByRow = cellsByRow.descendingMap();
    }
    List<RowResult<Set<Long>>> finalResults = cellsByRow.entrySet().stream().map(entry -> RowResult.create(entry.getKey(), entry.getValue())).collect(Collectors.toList());
    return SimpleTokenBackedResultsPage.create(result.getToken(), finalResults, result.mayHaveMoreResults());
}
Also used : ArrayListMultimap(com.google.common.collect.ArrayListMultimap) ImmutablePostgresDdlConfig(com.palantir.atlasdb.keyvalue.dbkvs.ImmutablePostgresDdlConfig) Arrays(java.util.Arrays) PalantirSqlException(com.palantir.exception.PalantirSqlException) Throwables(com.palantir.common.base.Throwables) CheckAndSetRequest(com.palantir.atlasdb.keyvalue.api.CheckAndSetRequest) OracleDdlConfig(com.palantir.atlasdb.keyvalue.dbkvs.OracleDdlConfig) Collections2(com.google.common.collect.Collections2) Map(java.util.Map) TableReference(com.palantir.atlasdb.keyvalue.api.TableReference) CandidateCellForSweeping(com.palantir.atlasdb.keyvalue.api.CandidateCellForSweeping) CellTsPairLoader(com.palantir.atlasdb.keyvalue.dbkvs.impl.sweep.CellTsPairLoader) AtlasDbConstants(com.palantir.atlasdb.AtlasDbConstants) DdlConfig(com.palantir.atlasdb.keyvalue.dbkvs.DdlConfig) AgnosticResultSet(com.palantir.nexus.db.sql.AgnosticResultSet) NamedThreadFactory(com.palantir.common.concurrent.NamedThreadFactory) Cell(com.palantir.atlasdb.keyvalue.api.Cell) Set(java.util.Set) AgnosticLightResultRow(com.palantir.nexus.db.sql.AgnosticLightResultRow) OracleGetRange(com.palantir.atlasdb.keyvalue.dbkvs.impl.oracle.OracleGetRange) CheckAndSetException(com.palantir.atlasdb.keyvalue.api.CheckAndSetException) KeyAlreadyExistsException(com.palantir.atlasdb.keyvalue.api.KeyAlreadyExistsException) Cells(com.palantir.atlasdb.keyvalue.impl.Cells) AbstractKeyValueService(com.palantir.atlasdb.keyvalue.impl.AbstractKeyValueService) ColumnRangeSelection(com.palantir.atlasdb.keyvalue.api.ColumnRangeSelection) Iterables(com.google.common.collect.Iterables) ParallelTaskRunner(com.palantir.atlasdb.keyvalue.dbkvs.impl.batch.ParallelTaskRunner) BatchingTaskRunner(com.palantir.atlasdb.keyvalue.dbkvs.impl.batch.BatchingTaskRunner) DbKvsPartitioners(com.palantir.atlasdb.keyvalue.dbkvs.util.DbKvsPartitioners) DbkvsVersionException(com.palantir.atlasdb.keyvalue.dbkvs.impl.postgres.DbkvsVersionException) PostgresPrefixedTableNames(com.palantir.atlasdb.keyvalue.dbkvs.impl.postgres.PostgresPrefixedTableNames) Supplier(java.util.function.Supplier) ArrayList(java.util.ArrayList) Multimaps(com.google.common.collect.Multimaps) LinkedHashMap(java.util.LinkedHashMap) ClusterAvailabilityStatus(com.palantir.atlasdb.keyvalue.api.ClusterAvailabilityStatus) SQLException(java.sql.SQLException) Lists(com.google.common.collect.Lists) Atomics(com.google.common.util.concurrent.Atomics) PostgresCellTsPageLoader(com.palantir.atlasdb.keyvalue.dbkvs.impl.postgres.PostgresCellTsPageLoader) Sha256Hash(com.palantir.util.crypto.Sha256Hash) Nullable(javax.annotation.Nullable) Functions(com.google.common.base.Functions) AbstractIterator(com.google.common.collect.AbstractIterator) DbKvsGetRange(com.palantir.atlasdb.keyvalue.dbkvs.impl.ranges.DbKvsGetRange) RowResult(com.palantir.atlasdb.keyvalue.api.RowResult) DbKvsGetCandidateCellsForSweeping(com.palantir.atlasdb.keyvalue.dbkvs.impl.sweep.DbKvsGetCandidateCellsForSweeping) PostgresDdlConfig(com.palantir.atlasdb.keyvalue.dbkvs.PostgresDdlConfig) Preconditions(com.google.common.base.Preconditions) LocalRowColumnRangeIterator(com.palantir.atlasdb.keyvalue.impl.LocalRowColumnRangeIterator) RangeRequests(com.palantir.atlasdb.keyvalue.api.RangeRequests) OracleCellTsPageLoader(com.palantir.atlasdb.keyvalue.dbkvs.impl.oracle.OracleCellTsPageLoader) Connection(java.sql.Connection) ImmediateSingleBatchTaskRunner(com.palantir.atlasdb.keyvalue.dbkvs.impl.batch.ImmediateSingleBatchTaskRunner) ListIterator(java.util.ListIterator) BatchColumnRangeSelection(com.palantir.atlasdb.keyvalue.api.BatchColumnRangeSelection) ClosableIterator(com.palantir.common.base.ClosableIterator) LoggerFactory(org.slf4j.LoggerFactory) RowColumnRangeIterator(com.palantir.atlasdb.keyvalue.api.RowColumnRangeIterator) BatchingStrategies(com.palantir.atlasdb.keyvalue.dbkvs.impl.batch.BatchingStrategies) PTExecutors(com.palantir.common.concurrent.PTExecutors) DbKvsGetRanges(com.palantir.atlasdb.keyvalue.dbkvs.impl.ranges.DbKvsGetRanges) Function(com.google.common.base.Function) ImmutableMap(com.google.common.collect.ImmutableMap) AbstractPagingIterable(com.palantir.util.paging.AbstractPagingIterable) Collection(java.util.Collection) AgnosticResultRow(com.palantir.nexus.db.sql.AgnosticResultRow) NavigableMap(java.util.NavigableMap) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue) 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) Objects(java.util.Objects) List(java.util.List) CandidateCellForSweepingRequest(com.palantir.atlasdb.keyvalue.api.CandidateCellForSweepingRequest) DbKeyValueServiceConfig(com.palantir.atlasdb.keyvalue.dbkvs.DbKeyValueServiceConfig) Entry(java.util.Map.Entry) Optional(java.util.Optional) OracleOverflowValueLoader(com.palantir.atlasdb.keyvalue.dbkvs.impl.oracle.OracleOverflowValueLoader) SortedMap(java.util.SortedMap) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) Stopwatch(com.google.common.base.Stopwatch) Output(com.palantir.common.annotation.Output) AccumulatorStrategies(com.palantir.atlasdb.keyvalue.dbkvs.impl.batch.AccumulatorStrategies) HashMap(java.util.HashMap) Multimap(com.google.common.collect.Multimap) AtomicReference(java.util.concurrent.atomic.AtomicReference) OracleTableNameGetter(com.palantir.atlasdb.keyvalue.dbkvs.OracleTableNameGetter) SqlConnection(com.palantir.nexus.db.sql.SqlConnection) Iterators(com.google.common.collect.Iterators) ImmutableList(com.google.common.collect.ImmutableList) Suppliers(com.google.common.base.Suppliers) Nonnull(javax.annotation.Nonnull) ClosableIterators(com.palantir.common.base.ClosableIterators) ExecutorService(java.util.concurrent.ExecutorService) Logger(org.slf4j.Logger) H2DdlConfig(com.palantir.atlasdb.keyvalue.dbkvs.H2DdlConfig) Iterator(java.util.Iterator) Value(com.palantir.atlasdb.keyvalue.api.Value) IterablePartitioner(com.palantir.atlasdb.keyvalue.impl.IterablePartitioner) TokenBackedBasicResultsPage(com.palantir.util.paging.TokenBackedBasicResultsPage) Maps(com.google.common.collect.Maps) TimeUnit(java.util.concurrent.TimeUnit) PostgresGetRange(com.palantir.atlasdb.keyvalue.dbkvs.impl.postgres.PostgresGetRange) Ordering(com.google.common.collect.Ordering) SimpleTokenBackedResultsPage(com.palantir.util.paging.SimpleTokenBackedResultsPage) Collections(java.util.Collections) AgnosticResultSet(com.palantir.nexus.db.sql.AgnosticResultSet) Set(java.util.Set) ColumnSelection(com.palantir.atlasdb.keyvalue.api.ColumnSelection) RowResult(com.palantir.atlasdb.keyvalue.api.RowResult) SortedMap(java.util.SortedMap) AgnosticLightResultRow(com.palantir.nexus.db.sql.AgnosticLightResultRow)

Example 14 with ColumnSelection

use of com.palantir.atlasdb.keyvalue.api.ColumnSelection in project atlasdb by palantir.

the class AbstractKeyValueServiceTest method testGetRowsWithSelectedColumns.

@Test
public void testGetRowsWithSelectedColumns() {
    putTestDataForSingleTimestamp();
    ColumnSelection columns1and2 = ColumnSelection.create(Arrays.asList(column1, column2));
    Map<Cell, Value> values = keyValueService.getRows(TEST_TABLE, Arrays.asList(row1, row2), columns1and2, TEST_TIMESTAMP + 1);
    assertEquals(3, values.size());
    assertNull(values.get(Cell.create(row1, column0)));
    assertArrayEquals(value12, values.get(Cell.create(row1, column2)).getContents());
    assertArrayEquals(value21, values.get(Cell.create(row2, column1)).getContents());
    assertArrayEquals(value22, values.get(Cell.create(row2, column2)).getContents());
}
Also used : ColumnSelection(com.palantir.atlasdb.keyvalue.api.ColumnSelection) Value(com.palantir.atlasdb.keyvalue.api.Value) Cell(com.palantir.atlasdb.keyvalue.api.Cell) Test(org.junit.Test)

Example 15 with ColumnSelection

use of com.palantir.atlasdb.keyvalue.api.ColumnSelection in project atlasdb by palantir.

the class SnapshotTransactionTest method testGetRowsLocalWritesWithColumnSelection.

@Test
public void testGetRowsLocalWritesWithColumnSelection() {
    // This test ensures getRows correctly applies columnSelection when there are local writes
    byte[] row1 = PtBytes.toBytes("row1");
    Cell row1Column1 = Cell.create(row1, PtBytes.toBytes("column1"));
    Cell row1Column2 = Cell.create(row1, PtBytes.toBytes("column2"));
    byte[] row1Column1Value = BigInteger.valueOf(1).toByteArray();
    byte[] row1Column2Value = BigInteger.valueOf(2).toByteArray();
    Transaction snapshotTx = serializableTxManager.createNewTransaction();
    snapshotTx.put(TABLE, ImmutableMap.of(row1Column1, row1Column1Value, row1Column2, row1Column2Value));
    ColumnSelection column1Selection = ColumnSelection.create(ImmutableList.of(row1Column1.getColumnName()));
    // local writes still apply columnSelection
    RowResult<byte[]> rowResult1 = snapshotTx.getRows(TABLE, ImmutableList.of(row1), column1Selection).get(row1);
    assertThat(rowResult1.getColumns(), hasEntry(row1Column1.getColumnName(), row1Column1Value));
    assertThat(rowResult1.getColumns(), not(hasEntry(row1Column2.getColumnName(), row1Column2Value)));
    RowResult<byte[]> rowResult2 = snapshotTx.getRows(TABLE, ImmutableList.of(row1), ColumnSelection.all()).get(row1);
    assertThat(rowResult2.getColumns(), hasEntry(row1Column1.getColumnName(), row1Column1Value));
    assertThat(rowResult2.getColumns(), hasEntry(row1Column2.getColumnName(), row1Column2Value));
}
Also used : ColumnSelection(com.palantir.atlasdb.keyvalue.api.ColumnSelection) Transaction(com.palantir.atlasdb.transaction.api.Transaction) Cell(com.palantir.atlasdb.keyvalue.api.Cell) Test(org.junit.Test)

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