Search in sources :

Example 1 with TableRowResult

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

the class TableRowResultDeserializer method deserialize.

@Override
public TableRowResult deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException {
    JsonNode node = jp.readValueAsTree();
    String tableName = node.get("table").textValue();
    Collection<RowResult<byte[]>> rowResults = Lists.newArrayList();
    TableMetadata metadata = metadataCache.getMetadata(tableName);
    for (JsonNode rowResult : node.get("data")) {
        byte[] row = AtlasDeserializers.deserializeRow(metadata.getRowMetadata(), rowResult.get("row"));
        ImmutableSortedMap.Builder<byte[], byte[]> cols = ImmutableSortedMap.orderedBy(UnsignedBytes.lexicographicalComparator());
        if (metadata.getColumns().hasDynamicColumns()) {
            for (JsonNode colVal : rowResult.get("cols")) {
                byte[] col = AtlasDeserializers.deserializeCol(metadata.getColumns(), colVal.get("col"));
                byte[] val = AtlasDeserializers.deserializeVal(metadata.getColumns().getDynamicColumn().getValue(), colVal.get("val"));
                cols.put(col, val);
            }
        } else {
            JsonNode namedCols = rowResult.get("cols");
            for (NamedColumnDescription namedCol : metadata.getColumns().getNamedColumns()) {
                JsonNode valNode = namedCols.get(namedCol.getLongName());
                if (valNode != null) {
                    byte[] col = namedCol.getShortName().getBytes(StandardCharsets.UTF_8);
                    byte[] val = AtlasDeserializers.deserializeVal(namedCol.getValue(), valNode);
                    cols.put(col, val);
                }
            }
        }
        rowResults.add(RowResult.create(row, cols.build()));
    }
    return new TableRowResult(tableName, rowResults);
}
Also used : TableMetadata(com.palantir.atlasdb.table.description.TableMetadata) TableRowResult(com.palantir.atlasdb.api.TableRowResult) RowResult(com.palantir.atlasdb.keyvalue.api.RowResult) TableRowResult(com.palantir.atlasdb.api.TableRowResult) ImmutableSortedMap(com.google.common.collect.ImmutableSortedMap) JsonNode(com.fasterxml.jackson.databind.JsonNode) NamedColumnDescription(com.palantir.atlasdb.table.description.NamedColumnDescription)

Example 2 with TableRowResult

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

the class AtlasConsoleServiceTest method testGetRows.

@Test
public void testGetRows() throws IOException {
    final TableRowSelection input = context.mock(TableRowSelection.class);
    final TableRowResult output = context.mock(TableRowResult.class);
    context.checking(fromJson(input, TableRowSelection.class));
    context.checking(new Expectations() {

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

Example 3 with TableRowResult

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

the class TransactionRemotingTest method testGetRowsNone.

@Test
public void testGetRowsNone() {
    setupFooStatus1("sweep.priority");
    TransactionToken txId = TransactionToken.autoCommit();
    TableRowResult badResults = service.getRows(txId, new TableRowSelection("sweep.priority", ImmutableList.of(new byte[1]), ColumnSelection.all()));
    Assert.assertTrue(Iterables.isEmpty(badResults.getResults()));
}
Also used : TableRowResult(com.palantir.atlasdb.api.TableRowResult) TableRowSelection(com.palantir.atlasdb.api.TableRowSelection) TransactionToken(com.palantir.atlasdb.api.TransactionToken) Test(org.junit.Test)

Example 4 with TableRowResult

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

the class TransactionRemotingTest method testGetRowsSome.

@Test
public void testGetRowsSome() {
    setupFooStatus1("sweep.priority");
    TransactionToken txId = TransactionToken.autoCommit();
    TableRowResult goodResults = service.getRows(txId, new TableRowSelection("sweep.priority", ImmutableList.of(SweepPriorityRow.of("foo").persistToBytes()), ColumnSelection.all()));
    SweepPriorityRowResult result = SweepPriorityRowResult.of(Iterables.getOnlyElement(goodResults.getResults()));
    Assert.assertEquals(1L, result.getCellsExamined().longValue());
}
Also used : TableRowResult(com.palantir.atlasdb.api.TableRowResult) TableRowSelection(com.palantir.atlasdb.api.TableRowSelection) TransactionToken(com.palantir.atlasdb.api.TransactionToken) SweepPriorityRowResult(com.palantir.atlasdb.schema.generated.SweepPriorityTable.SweepPriorityRowResult) Test(org.junit.Test)

Example 5 with TableRowResult

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

the class RangeTokenDeserializer method deserialize.

@Override
public RangeToken deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException {
    JsonToken jsonToken = jp.getCurrentToken();
    if (jsonToken == JsonToken.START_OBJECT) {
        jsonToken = jp.nextToken();
    }
    TableRowResult results = null;
    TableRange nextRange = null;
    for (; jsonToken == JsonToken.FIELD_NAME; jsonToken = jp.nextToken()) {
        String fieldName = jp.getCurrentName();
        jsonToken = jp.nextToken();
        if (fieldName.equals("data")) {
            results = jp.readValueAs(TableRowResult.class);
        } else if (fieldName.equals("next")) {
            nextRange = jp.readValueAs(TableRange.class);
        }
    }
    return new RangeToken(results, nextRange);
}
Also used : TableRowResult(com.palantir.atlasdb.api.TableRowResult) RangeToken(com.palantir.atlasdb.api.RangeToken) TableRange(com.palantir.atlasdb.api.TableRange) JsonToken(com.fasterxml.jackson.core.JsonToken)

Aggregations

TableRowResult (com.palantir.atlasdb.api.TableRowResult)7 TableRowSelection (com.palantir.atlasdb.api.TableRowSelection)4 Test (org.junit.Test)3 RangeToken (com.palantir.atlasdb.api.RangeToken)2 TableRange (com.palantir.atlasdb.api.TableRange)2 TransactionToken (com.palantir.atlasdb.api.TransactionToken)2 RowResult (com.palantir.atlasdb.keyvalue.api.RowResult)2 JsonToken (com.fasterxml.jackson.core.JsonToken)1 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 ImmutableSortedMap (com.google.common.collect.ImmutableSortedMap)1 RangeRequest (com.palantir.atlasdb.keyvalue.api.RangeRequest)1 SweepPriorityRowResult (com.palantir.atlasdb.schema.generated.SweepPriorityTable.SweepPriorityRowResult)1 NamedColumnDescription (com.palantir.atlasdb.table.description.NamedColumnDescription)1 TableMetadata (com.palantir.atlasdb.table.description.TableMetadata)1 Expectations (org.jmock.Expectations)1