Search in sources :

Example 36 with RowResult

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

the class KvsGetRangeBenchmarks method getSingleRangeInner.

private Object getSingleRangeInner(ConsecutiveNarrowTable table, int sliceSize) {
    RangeRequest request = Iterables.getOnlyElement(table.getRangeRequests(1, sliceSize, false));
    int startRow = Ints.fromByteArray(request.getStartInclusive());
    ClosableIterator<RowResult<Value>> result = table.getKvs().getRange(table.getTableRef(), request, Long.MAX_VALUE);
    ArrayList<RowResult<Value>> list = Lists.newArrayList(result);
    result.close();
    Preconditions.checkState(list.size() == sliceSize, "List size %s != %s", sliceSize, list.size());
    list.forEach(rowResult -> {
        byte[] rowName = rowResult.getRowName();
        int rowNumber = Ints.fromByteArray(rowName);
        Preconditions.checkState(rowNumber - startRow < sliceSize, "Start Row %s, row number %s, sliceSize %s", startRow, rowNumber, sliceSize);
    });
    return result;
}
Also used : RowResult(com.palantir.atlasdb.keyvalue.api.RowResult) RangeRequest(com.palantir.atlasdb.keyvalue.api.RangeRequest)

Example 37 with RowResult

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

the class JdbcKeyValueService method getRangeOfTimestamps.

@Override
public ClosableIterator<RowResult<Set<Long>>> getRangeOfTimestamps(final TableReference tableRef, final RangeRequest rangeRequest, final long timestamp) {
    Iterable<RowResult<Set<Long>>> iter = new AbstractPagingIterable<RowResult<Set<Long>>, TokenBackedBasicResultsPage<RowResult<Set<Long>>, byte[]>>() {

        @Override
        protected TokenBackedBasicResultsPage<RowResult<Set<Long>>, byte[]> getFirstPage() {
            return getPageWithTimestamps(tableRef, rangeRequest, timestamp);
        }

        @Override
        protected TokenBackedBasicResultsPage<RowResult<Set<Long>>, byte[]> getNextPage(TokenBackedBasicResultsPage<RowResult<Set<Long>>, byte[]> previous) {
            byte[] startRow = previous.getTokenForNextPage();
            RangeRequest newRange = rangeRequest.getBuilder().startRowInclusive(startRow).build();
            return getPageWithTimestamps(tableRef, newRange, timestamp);
        }
    };
    return ClosableIterators.wrap(iter.iterator());
}
Also used : RowResult(com.palantir.atlasdb.keyvalue.api.RowResult) TokenBackedBasicResultsPage(com.palantir.util.paging.TokenBackedBasicResultsPage) Set(java.util.Set) ImmutableSet(com.google.common.collect.ImmutableSet) RangeRequest(com.palantir.atlasdb.keyvalue.api.RangeRequest) AbstractPagingIterable(com.palantir.util.paging.AbstractPagingIterable)

Example 38 with RowResult

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

the class AbstractKeyValueServiceTest method testGetRange.

public void testGetRange(boolean reverseSupported) {
    putTestDataForSingleTimestamp();
    // Unbounded
    final RangeRequest all = RangeRequest.all();
    assertRangeSizeAndOrdering(keyValueService.getRange(TEST_TABLE, all, TEST_TIMESTAMP + 1), 3, all);
    if (reverseSupported) {
        final RangeRequest allReverse = RangeRequest.reverseBuilder().build();
        assertRangeSizeAndOrdering(keyValueService.getRange(TEST_TABLE, allReverse, TEST_TIMESTAMP + 1), 3, allReverse);
    }
    // Upbounded
    final RangeRequest upbounded = RangeRequest.builder().endRowExclusive(row2).build();
    assertRangeSizeAndOrdering(keyValueService.getRange(TEST_TABLE, upbounded, TEST_TIMESTAMP + 1), 2, upbounded);
    if (reverseSupported) {
        final RangeRequest upboundedReverse = RangeRequest.reverseBuilder().endRowExclusive(row0).build();
        assertRangeSizeAndOrdering(keyValueService.getRange(TEST_TABLE, upboundedReverse, TEST_TIMESTAMP + 1), 2, upboundedReverse);
    }
    // Downbounded
    final RangeRequest downbounded = RangeRequest.builder().startRowInclusive(row1).build();
    assertRangeSizeAndOrdering(keyValueService.getRange(TEST_TABLE, downbounded, TEST_TIMESTAMP + 1), 2, downbounded);
    if (reverseSupported) {
        final RangeRequest downboundedReverse = RangeRequest.reverseBuilder().startRowInclusive(row1).build();
        assertRangeSizeAndOrdering(keyValueService.getRange(TEST_TABLE, downboundedReverse, TEST_TIMESTAMP + 1), 2, downboundedReverse);
    }
    // Both-bounded
    final RangeRequest bothbounded = RangeRequest.builder().startRowInclusive(row1).endRowExclusive(row2).build();
    assertRangeSizeAndOrdering(keyValueService.getRange(TEST_TABLE, bothbounded, TEST_TIMESTAMP + 1), 1, bothbounded);
    if (reverseSupported) {
        final RangeRequest bothboundedReverse = RangeRequest.reverseBuilder().startRowInclusive(row2).endRowExclusive(row1).build();
        assertRangeSizeAndOrdering(keyValueService.getRange(TEST_TABLE, bothboundedReverse, TEST_TIMESTAMP + 1), 1, bothboundedReverse);
    }
    // Precise test for lower-bounded
    RangeRequest rangeRequest = downbounded;
    ClosableIterator<RowResult<Value>> rangeResult = keyValueService.getRange(TEST_TABLE, rangeRequest, TEST_TIMESTAMP + 1);
    assertFalse(keyValueService.getRange(TEST_TABLE, rangeRequest, TEST_TIMESTAMP).hasNext());
    assertTrue(rangeResult.hasNext());
    assertEquals(RowResult.create(row1, ImmutableSortedMap.orderedBy(UnsignedBytes.lexicographicalComparator()).put(column0, Value.create(value10, TEST_TIMESTAMP)).put(column2, Value.create(value12, TEST_TIMESTAMP)).build()), rangeResult.next());
    assertTrue(rangeResult.hasNext());
    assertEquals(RowResult.create(row2, ImmutableSortedMap.orderedBy(UnsignedBytes.lexicographicalComparator()).put(column1, Value.create(value21, TEST_TIMESTAMP)).put(column2, Value.create(value22, TEST_TIMESTAMP)).build()), rangeResult.next());
    rangeResult.close();
}
Also used : RowResult(com.palantir.atlasdb.keyvalue.api.RowResult) RangeRequest(com.palantir.atlasdb.keyvalue.api.RangeRequest)

Example 39 with RowResult

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

the class AbstractKeyValueServiceTest method doTestGetRangePagingWithColumnSelection.

private void doTestGetRangePagingWithColumnSelection(int batchSizeHint, int numRows, int numColsInSelection, boolean reverse) {
    Collection<byte[]> columnSelection = new ArrayList<>(numColsInSelection);
    for (long col = 1; col <= numColsInSelection; ++col) {
        byte[] colName = PtBytes.toBytes(Long.MIN_VALUE ^ col);
        columnSelection.add(colName);
    }
    RangeRequest request = RangeRequest.builder(reverse).retainColumns(columnSelection).batchHint(batchSizeHint).build();
    try (ClosableIterator<RowResult<Value>> iter = keyValueService.getRange(TEST_TABLE, request, TEST_TIMESTAMP + 1)) {
        List<RowResult<Value>> results = ImmutableList.copyOf(iter);
        assertEquals(getExpectedResultForRangePagingWithColumnSelectionTest(numRows, numColsInSelection, reverse), results);
    }
}
Also used : RowResult(com.palantir.atlasdb.keyvalue.api.RowResult) RangeRequest(com.palantir.atlasdb.keyvalue.api.RangeRequest) ArrayList(java.util.ArrayList)

Example 40 with RowResult

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

the class AbstractKeyValueServiceTest method testGetRangeWithTimestamps.

private void testGetRangeWithTimestamps(boolean reverse) {
    putTestDataForMultipleTimestamps();
    final RangeRequest range;
    if (!reverse) {
        range = RangeRequest.builder().startRowInclusive(row0).endRowExclusive(row1).build();
    } else {
        range = RangeRequest.reverseBuilder().startRowInclusive(row0).build();
    }
    ClosableIterator<RowResult<Set<Long>>> rangeWithHistory = keyValueService.getRangeOfTimestamps(TEST_TABLE, range, TEST_TIMESTAMP + 2);
    RowResult<Set<Long>> row = rangeWithHistory.next();
    assertFalse(rangeWithHistory.hasNext());
    rangeWithHistory.close();
    assertEquals(1, Iterables.size(row.getCells()));
    Entry<Cell, Set<Long>> cell0 = row.getCells().iterator().next();
    assertEquals(2, cell0.getValue().size());
    assertTrue(cell0.getValue().contains(TEST_TIMESTAMP));
    assertTrue(cell0.getValue().contains(TEST_TIMESTAMP + 1));
}
Also used : RowResult(com.palantir.atlasdb.keyvalue.api.RowResult) ImmutableSet(com.google.common.collect.ImmutableSet) Set(java.util.Set) RangeRequest(com.palantir.atlasdb.keyvalue.api.RangeRequest) Cell(com.palantir.atlasdb.keyvalue.api.Cell)

Aggregations

RowResult (com.palantir.atlasdb.keyvalue.api.RowResult)57 RangeRequest (com.palantir.atlasdb.keyvalue.api.RangeRequest)40 Test (org.junit.Test)23 Cell (com.palantir.atlasdb.keyvalue.api.Cell)17 Value (com.palantir.atlasdb.keyvalue.api.Value)16 TableReference (com.palantir.atlasdb.keyvalue.api.TableReference)10 TokenBackedBasicResultsPage (com.palantir.util.paging.TokenBackedBasicResultsPage)10 Set (java.util.Set)8 ColumnSelection (com.palantir.atlasdb.keyvalue.api.ColumnSelection)7 Transaction (com.palantir.atlasdb.transaction.api.Transaction)7 SortedMap (java.util.SortedMap)7 Map (java.util.Map)6 ImmutableSet (com.google.common.collect.ImmutableSet)5 Lists (com.google.common.collect.Lists)5 AbstractPagingIterable (com.palantir.util.paging.AbstractPagingIterable)5 Entry (java.util.Map.Entry)5 ImmutableList (com.google.common.collect.ImmutableList)4 ImmutableSortedMap (com.google.common.collect.ImmutableSortedMap)4 PtBytes (com.palantir.atlasdb.encoding.PtBytes)4 ClosableIterator (com.palantir.common.base.ClosableIterator)4