Search in sources :

Example 36 with RangeRequest

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

the class AbstractSchemaApiTest method testRowRangeSecondColumnFirstTwoResults.

@Test
public void testRowRangeSecondColumnFirstTwoResults() {
    AbstractTransaction transaction = mock(AbstractTransaction.class);
    Cell expectedCell = getCell(TEST_ROW_KEY, SECOND_COL_SHORT_NAME);
    Cell anotherExpectedCell = getCell(TEST_ROW_KEY2, SECOND_COL_SHORT_NAME);
    Cell cellToBeDroppedFromResults = getCell(TEST_ROW_KEY3, SECOND_COL_SHORT_NAME);
    RangeRequest expectedRange = RangeRequest.builder().startRowInclusive(TEST_ROW_KEY.getBytes()).endRowExclusive(RANGE_END_ROW_KEY.getBytes()).retainColumns(SECOND_COLUMN_SELECTION).batchHint(2).build();
    when(transaction.getRange(tableRef, expectedRange)).thenReturn(BatchingVisitableFromIterable.create(Arrays.asList(RowResult.of(expectedCell, STRING_VALUE_PERSISTER.persistToBytes(TEST_VALUE_STRING)), RowResult.of(anotherExpectedCell, STRING_VALUE_PERSISTER.persistToBytes(TEST_VALUE_STRING2)), RowResult.of(cellToBeDroppedFromResults, STRING_VALUE_PERSISTER.persistToBytes(TEST_VALUE_STRING3)))));
    Map<String, StringValue> result = getRangeSecondColumnOnlyFirstTwoResults(transaction, TEST_ROW_KEY, RANGE_END_ROW_KEY);
    assertThat(result).isEqualTo(ImmutableMap.of(TEST_ROW_KEY, TEST_VALUE_STRING, TEST_ROW_KEY2, TEST_VALUE_STRING2));
    verify(transaction, times(1)).getRange(tableRef, expectedRange);
}
Also used : RangeRequest(com.palantir.atlasdb.keyvalue.api.RangeRequest) AbstractTransaction(com.palantir.atlasdb.transaction.impl.AbstractTransaction) StringValue(com.palantir.atlasdb.table.description.test.StringValue) Cell(com.palantir.atlasdb.keyvalue.api.Cell) Test(org.junit.Test)

Example 37 with RangeRequest

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

the class SweepStatsKeyValueServiceTest method otherDeleteRangeDoesNotCountAsClearingTheTable.

@Test
public void otherDeleteRangeDoesNotCountAsClearingTheTable() throws Exception {
    RangeRequest request = RangeRequest.builder().startRowInclusive(ROW).build();
    kvs.deleteRange(TABLE, request);
    assertFalse(kvs.hasBeenCleared(TABLE));
}
Also used : RangeRequest(com.palantir.atlasdb.keyvalue.api.RangeRequest) Test(org.junit.Test)

Example 38 with RangeRequest

use of com.palantir.atlasdb.keyvalue.api.RangeRequest 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 39 with RangeRequest

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

the class WhereClausesTest method withReverseRange.

@Test
public void withReverseRange() {
    RangeRequest request = RangeRequest.reverseBuilder().startRowInclusive(END).endRowExclusive(START).build();
    WhereClauses whereClauses = WhereClauses.create("i", request);
    List<String> expectedClauses = ImmutableList.of("i.row_name <= ?", "i.row_name > ?");
    assertEquals(whereClauses.getClauses(), expectedClauses);
    checkWhereArguments(whereClauses, ImmutableList.of(END, START));
}
Also used : RangeRequest(com.palantir.atlasdb.keyvalue.api.RangeRequest) Test(org.junit.Test)

Example 40 with RangeRequest

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

the class WhereClausesTest method whereClausesWithExtraClause.

@Test
public void whereClausesWithExtraClause() {
    RangeRequest request = RangeRequest.builder().startRowInclusive(START).endRowExclusive(END).build();
    String extraClause = "i.foo = bar";
    WhereClauses whereClauses = WhereClauses.create("i", request, extraClause);
    List<String> expectedClauses = ImmutableList.of("i.row_name >= ?", "i.row_name < ?", extraClause);
    assertEquals(whereClauses.getClauses(), expectedClauses);
    checkWhereArguments(whereClauses, ImmutableList.of(START, END));
}
Also used : RangeRequest(com.palantir.atlasdb.keyvalue.api.RangeRequest) Test(org.junit.Test)

Aggregations

RangeRequest (com.palantir.atlasdb.keyvalue.api.RangeRequest)68 RowResult (com.palantir.atlasdb.keyvalue.api.RowResult)36 Test (org.junit.Test)35 Value (com.palantir.atlasdb.keyvalue.api.Value)17 TokenBackedBasicResultsPage (com.palantir.util.paging.TokenBackedBasicResultsPage)14 Cell (com.palantir.atlasdb.keyvalue.api.Cell)12 Transaction (com.palantir.atlasdb.transaction.api.Transaction)7 List (java.util.List)5 Set (java.util.Set)5 TableReference (com.palantir.atlasdb.keyvalue.api.TableReference)4 StringValue (com.palantir.atlasdb.table.description.test.StringValue)4 AbstractPagingIterable (com.palantir.util.paging.AbstractPagingIterable)4 Map (java.util.Map)4 ColumnSelection (com.palantir.atlasdb.keyvalue.api.ColumnSelection)3 AbstractIterator (com.google.common.collect.AbstractIterator)2 ImmutableSet (com.google.common.collect.ImmutableSet)2 Hashing (com.google.common.hash.Hashing)2 NameComponentDescription (com.palantir.atlasdb.table.description.NameComponentDescription)2 BatchingVisitableView (com.palantir.common.base.BatchingVisitableView)2 ClosableIterator (com.palantir.common.base.ClosableIterator)2