Search in sources :

Example 51 with RangeRequest

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

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

Example 53 with RangeRequest

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

the class AbstractKeyValueServiceTest method doTestGetRangePaging.

private void doTestGetRangePaging(int numColumnsInMetadata, int batchSizeHint, boolean reverse) {
    TableReference tableRef = createTableWithNamedColumns(numColumnsInMetadata);
    Map<Cell, byte[]> values = new HashMap<Cell, byte[]>();
    values.put(Cell.create(PtBytes.toBytes("00"), PtBytes.toBytes("c1")), PtBytes.toBytes("a"));
    values.put(Cell.create(PtBytes.toBytes("00"), PtBytes.toBytes("c2")), PtBytes.toBytes("b"));
    values.put(Cell.create(PtBytes.toBytes("01"), RangeRequests.getFirstRowName()), PtBytes.toBytes("c"));
    values.put(Cell.create(PtBytes.toBytes("02"), PtBytes.toBytes("c1")), PtBytes.toBytes("d"));
    values.put(Cell.create(PtBytes.toBytes("02"), PtBytes.toBytes("c2")), PtBytes.toBytes("e"));
    values.put(Cell.create(PtBytes.toBytes("03"), PtBytes.toBytes("c1")), PtBytes.toBytes("f"));
    values.put(Cell.create(PtBytes.toBytes("04"), PtBytes.toBytes("c1")), PtBytes.toBytes("g"));
    values.put(Cell.create(PtBytes.toBytes("04"), RangeRequests.getLastRowName()), PtBytes.toBytes("h"));
    values.put(Cell.create(PtBytes.toBytes("05"), PtBytes.toBytes("c1")), PtBytes.toBytes("i"));
    values.put(Cell.create(RangeRequests.getLastRowName(), PtBytes.toBytes("c1")), PtBytes.toBytes("j"));
    keyValueService.put(tableRef, values, TEST_TIMESTAMP);
    RangeRequest request = RangeRequest.builder(reverse).batchHint(batchSizeHint).build();
    try (ClosableIterator<RowResult<Value>> iter = keyValueService.getRange(tableRef, request, Long.MAX_VALUE)) {
        List<RowResult<Value>> results = ImmutableList.copyOf(iter);
        List<RowResult<Value>> expected = ImmutableList.of(RowResult.create(PtBytes.toBytes("00"), ImmutableSortedMap.<byte[], Value>orderedBy(UnsignedBytes.lexicographicalComparator()).put(PtBytes.toBytes("c1"), Value.create(PtBytes.toBytes("a"), TEST_TIMESTAMP)).put(PtBytes.toBytes("c2"), Value.create(PtBytes.toBytes("b"), TEST_TIMESTAMP)).build()), RowResult.create(PtBytes.toBytes("01"), ImmutableSortedMap.<byte[], Value>orderedBy(UnsignedBytes.lexicographicalComparator()).put(RangeRequests.getFirstRowName(), Value.create(PtBytes.toBytes("c"), TEST_TIMESTAMP)).build()), RowResult.create(PtBytes.toBytes("02"), ImmutableSortedMap.<byte[], Value>orderedBy(UnsignedBytes.lexicographicalComparator()).put(PtBytes.toBytes("c1"), Value.create(PtBytes.toBytes("d"), TEST_TIMESTAMP)).put(PtBytes.toBytes("c2"), Value.create(PtBytes.toBytes("e"), TEST_TIMESTAMP)).build()), RowResult.create(PtBytes.toBytes("03"), ImmutableSortedMap.<byte[], Value>orderedBy(UnsignedBytes.lexicographicalComparator()).put(PtBytes.toBytes("c1"), Value.create(PtBytes.toBytes("f"), TEST_TIMESTAMP)).build()), RowResult.create(PtBytes.toBytes("04"), ImmutableSortedMap.<byte[], Value>orderedBy(UnsignedBytes.lexicographicalComparator()).put(PtBytes.toBytes("c1"), Value.create(PtBytes.toBytes("g"), TEST_TIMESTAMP)).put(RangeRequests.getLastRowName(), Value.create(PtBytes.toBytes("h"), TEST_TIMESTAMP)).build()), RowResult.create(PtBytes.toBytes("05"), ImmutableSortedMap.<byte[], Value>orderedBy(UnsignedBytes.lexicographicalComparator()).put(PtBytes.toBytes("c1"), Value.create(PtBytes.toBytes("i"), TEST_TIMESTAMP)).build()), RowResult.create(RangeRequests.getLastRowName(), ImmutableSortedMap.<byte[], Value>orderedBy(UnsignedBytes.lexicographicalComparator()).put(PtBytes.toBytes("c1"), Value.create(PtBytes.toBytes("j"), TEST_TIMESTAMP)).build()));
        assertEquals(reverse ? Lists.reverse(expected) : expected, results);
    }
}
Also used : RowResult(com.palantir.atlasdb.keyvalue.api.RowResult) TableReference(com.palantir.atlasdb.keyvalue.api.TableReference) HashMap(java.util.HashMap) RangeRequest(com.palantir.atlasdb.keyvalue.api.RangeRequest) Value(com.palantir.atlasdb.keyvalue.api.Value) Cell(com.palantir.atlasdb.keyvalue.api.Cell)

Example 54 with RangeRequest

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

the class AtlasDbServiceImpl method getRange.

@Override
public RangeToken getRange(TransactionToken token, final TableRange range) {
    return runReadOnly(token, transaction -> {
        int limit = range.getBatchSize() + 1;
        RangeRequest request = RangeRequest.builder().startRowInclusive(range.getStartRow()).endRowExclusive(range.getEndRow()).batchHint(limit).retainColumns(range.getColumns()).build();
        BatchingVisitable<RowResult<byte[]>> visitable = transaction.getRange(getTableRef(range.getTableName()), request);
        List<RowResult<byte[]>> results = BatchingVisitables.limit(visitable, limit).immutableCopy();
        if (results.size() == limit) {
            TableRowResult data = new TableRowResult(range.getTableName(), results.subList(0, limit - 1));
            RowResult<byte[]> lastResultInBatch = results.get(limit - 1);
            TableRange nextRange = range.withStartRow(lastResultInBatch.getRowName());
            return new RangeToken(data, nextRange);
        } else {
            TableRowResult data = new TableRowResult(range.getTableName(), results);
            return new RangeToken(data, null);
        }
    });
}
Also used : TableRowResult(com.palantir.atlasdb.api.TableRowResult) RowResult(com.palantir.atlasdb.keyvalue.api.RowResult) TableRowResult(com.palantir.atlasdb.api.TableRowResult) RangeRequest(com.palantir.atlasdb.keyvalue.api.RangeRequest) RangeToken(com.palantir.atlasdb.api.RangeToken) TableRange(com.palantir.atlasdb.api.TableRange)

Example 55 with RangeRequest

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

the class TransactionGetBenchmarks method getSingleRowWithRangeQueryInner.

private List<RowResult<byte[]>> getSingleRowWithRangeQueryInner(final ConsecutiveNarrowTable table) {
    return table.getTransactionManager().runTaskThrowOnConflict(txn -> {
        RangeRequest request = Iterables.getOnlyElement(table.getRangeRequests(1, 1, false));
        List<RowResult<byte[]>> result = BatchingVisitables.copyToList(txn.getRange(table.getTableRef(), request));
        byte[] rowName = Iterables.getOnlyElement(result).getRowName();
        int rowNumber = ConsecutiveNarrowTable.rowNumber(rowName);
        int expectedRowNumber = ConsecutiveNarrowTable.rowNumber(request.getStartInclusive());
        Preconditions.checkState(rowNumber == expectedRowNumber, "Start Row %s, row number %s", expectedRowNumber, rowNumber);
        return result;
    });
}
Also used : RowResult(com.palantir.atlasdb.keyvalue.api.RowResult) RangeRequest(com.palantir.atlasdb.keyvalue.api.RangeRequest)

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