Search in sources :

Example 6 with TableRange

use of com.palantir.atlasdb.api.TableRange in project atlasdb by palantir.

the class AtlasConsoleServiceTest method testGetRange.

@Test
public void testGetRange() throws IOException {
    final TableRange input = context.mock(TableRange.class);
    final RangeToken output = context.mock(RangeToken.class);
    context.checking(fromJson(input, TableRange.class));
    context.checking(new Expectations() {

        {
            oneOf(delegate).getRange(token, input);
            will(returnValue(output));
        }
    });
    context.checking(toJson(output, RangeToken.class));
    assertEquals(service.getRange(token, QUERY), RESULT);
    context.assertIsSatisfied();
}
Also used : Expectations(org.jmock.Expectations) RangeToken(com.palantir.atlasdb.api.RangeToken) TableRange(com.palantir.atlasdb.api.TableRange) Test(org.junit.Test)

Example 7 with TableRange

use of com.palantir.atlasdb.api.TableRange in project atlasdb by palantir.

the class TransactionRemotingTest method testGetRangeNone.

@Test
public void testGetRangeNone() {
    setupFooStatus1("sweep.priority");
    TransactionToken token = TransactionToken.autoCommit();
    RangeToken range = service.getRange(token, new TableRange("sweep.priority", new byte[1], new byte[2], ImmutableList.<byte[]>of(), 10));
    Assert.assertTrue(Iterables.isEmpty(range.getResults().getResults()));
    Assert.assertNull(range.getNextRange());
}
Also used : TransactionToken(com.palantir.atlasdb.api.TransactionToken) RangeToken(com.palantir.atlasdb.api.RangeToken) TableRange(com.palantir.atlasdb.api.TableRange) Test(org.junit.Test)

Example 8 with TableRange

use of com.palantir.atlasdb.api.TableRange in project atlasdb by palantir.

the class TransactionRemotingTest method testDelete.

@Test
public void testDelete() {
    setupFooStatus1("sweep.priority");
    Map<Cell, byte[]> contents = getSweepPriorityTableContents("foo");
    TransactionToken token = TransactionToken.autoCommit();
    service.delete(token, new TableCell("sweep.priority", contents.keySet()));
    RangeToken range = service.getRange(token, new TableRange("sweep.priority", new byte[0], new byte[0], ImmutableList.<byte[]>of(), 10));
    Assert.assertTrue(Iterables.isEmpty(range.getResults().getResults()));
    Assert.assertNull(range.getNextRange());
}
Also used : TableCell(com.palantir.atlasdb.api.TableCell) TransactionToken(com.palantir.atlasdb.api.TransactionToken) RangeToken(com.palantir.atlasdb.api.RangeToken) TableRange(com.palantir.atlasdb.api.TableRange) Cell(com.palantir.atlasdb.keyvalue.api.Cell) TableCell(com.palantir.atlasdb.api.TableCell) Test(org.junit.Test)

Example 9 with TableRange

use of com.palantir.atlasdb.api.TableRange 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 10 with TableRange

use of com.palantir.atlasdb.api.TableRange in project atlasdb by palantir.

the class TableRangeDeserializer method deserialize.

@Override
public TableRange deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException {
    JsonNode node = jp.readValueAsTree();
    String tableName = node.get("table").textValue();
    TableMetadata metadata = metadataCache.getMetadata(tableName);
    JsonNode optBatchSize = node.get("batch_size");
    int batchSize = optBatchSize == null ? 2000 : optBatchSize.asInt();
    Iterable<byte[]> columns = AtlasDeserializers.deserializeNamedCols(metadata.getColumns(), node.get("cols"));
    byte[] startRow = new byte[0];
    byte[] endRow = new byte[0];
    if (node.has("prefix")) {
        startRow = AtlasDeserializers.deserializeRowPrefix(metadata.getRowMetadata(), node.get("prefix"));
        endRow = RangeRequests.createEndNameForPrefixScan(startRow);
    } else {
        if (node.has("raw_start")) {
            startRow = node.get("raw_start").binaryValue();
        } else if (node.has("start")) {
            startRow = AtlasDeserializers.deserializeRow(metadata.getRowMetadata(), node.get("start"));
        }
        if (node.has("raw_end")) {
            endRow = node.get("raw_end").binaryValue();
        } else if (node.has("end")) {
            endRow = AtlasDeserializers.deserializeRow(metadata.getRowMetadata(), node.get("end"));
        }
    }
    return new TableRange(tableName, startRow, endRow, columns, batchSize);
}
Also used : TableMetadata(com.palantir.atlasdb.table.description.TableMetadata) TableRange(com.palantir.atlasdb.api.TableRange) JsonNode(com.fasterxml.jackson.databind.JsonNode)

Aggregations

TableRange (com.palantir.atlasdb.api.TableRange)10 RangeToken (com.palantir.atlasdb.api.RangeToken)9 Test (org.junit.Test)6 TransactionToken (com.palantir.atlasdb.api.TransactionToken)5 TableRowResult (com.palantir.atlasdb.api.TableRowResult)2 JsonToken (com.fasterxml.jackson.core.JsonToken)1 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 TableCell (com.palantir.atlasdb.api.TableCell)1 TableCellVal (com.palantir.atlasdb.api.TableCellVal)1 Cell (com.palantir.atlasdb.keyvalue.api.Cell)1 RangeRequest (com.palantir.atlasdb.keyvalue.api.RangeRequest)1 RowResult (com.palantir.atlasdb.keyvalue.api.RowResult)1 SweepPriorityRowResult (com.palantir.atlasdb.schema.generated.SweepPriorityTable.SweepPriorityRowResult)1 TableMetadata (com.palantir.atlasdb.table.description.TableMetadata)1 Expectations (org.jmock.Expectations)1