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);
}
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();
}
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()));
}
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());
}
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);
}
Aggregations