Search in sources :

Example 6 with ColumnMetadataDescription

use of com.palantir.atlasdb.table.description.ColumnMetadataDescription in project atlasdb by palantir.

the class TableRowResultSerializer method serialize.

private static void serialize(JsonGenerator jgen, TableMetadata metadata, RowResult<byte[]> result) throws IOException {
    jgen.writeStartObject();
    AtlasSerializers.serializeRow(jgen, metadata.getRowMetadata(), result.getRowName());
    ColumnMetadataDescription columns = metadata.getColumns();
    if (columns.hasDynamicColumns()) {
        jgen.writeArrayFieldStart("cols");
        for (Entry<byte[], byte[]> colVal : result.getColumns().entrySet()) {
            jgen.writeStartObject();
            byte[] col = colVal.getKey();
            byte[] val = colVal.getValue();
            DynamicColumnDescription dynamicColumn = columns.getDynamicColumn();
            AtlasSerializers.serializeDynamicColumn(jgen, dynamicColumn, col);
            jgen.writeFieldName("val");
            AtlasSerializers.serializeVal(jgen, dynamicColumn.getValue(), val);
            jgen.writeEndObject();
        }
        jgen.writeEndArray();
    } else {
        jgen.writeObjectFieldStart("cols");
        SortedMap<byte[], byte[]> columnValues = result.getColumns();
        Set<NamedColumnDescription> namedColumns = columns.getNamedColumns();
        for (NamedColumnDescription description : namedColumns) {
            byte[] col = PtBytes.toCachedBytes(description.getShortName());
            byte[] val = columnValues.get(col);
            if (val != null) {
                AtlasSerializers.serializeNamedCol(jgen, description, val);
            }
        }
        jgen.writeEndObject();
    }
    jgen.writeEndObject();
}
Also used : ColumnMetadataDescription(com.palantir.atlasdb.table.description.ColumnMetadataDescription) DynamicColumnDescription(com.palantir.atlasdb.table.description.DynamicColumnDescription) NamedColumnDescription(com.palantir.atlasdb.table.description.NamedColumnDescription)

Example 7 with ColumnMetadataDescription

use of com.palantir.atlasdb.table.description.ColumnMetadataDescription in project atlasdb by palantir.

the class AtlasDeserializers method deserializeCellVal.

private static Iterable<Entry<Cell, byte[]>> deserializeCellVal(TableMetadata metadata, JsonNode node) {
    byte[] row = deserializeRow(metadata.getRowMetadata(), node.get("row"));
    ColumnMetadataDescription colDescription = metadata.getColumns();
    if (colDescription.hasDynamicColumns()) {
        byte[] col = deserializeDynamicCol(colDescription.getDynamicColumn(), node.get("col"));
        byte[] val = deserializeVal(colDescription.getDynamicColumn().getValue(), node.get("val"));
        return ImmutableList.of(Maps.immutableEntry(Cell.create(row, col), val));
    } else {
        Collection<Entry<Cell, byte[]>> results = Lists.newArrayListWithCapacity(1);
        Iterator<Entry<String, JsonNode>> fields = node.fields();
        while (fields.hasNext()) {
            Entry<String, JsonNode> entry = fields.next();
            String longName = entry.getKey();
            if (longName.equals("row")) {
                continue;
            }
            NamedColumnDescription description = getNamedCol(colDescription, longName);
            byte[] col = PtBytes.toCachedBytes(description.getShortName());
            JsonNode valNode = entry.getValue();
            byte[] val = deserializeVal(description.getValue(), valNode);
            results.add(Maps.immutableEntry(Cell.create(row, col), val));
        }
        return results;
    }
}
Also used : Entry(java.util.Map.Entry) ColumnMetadataDescription(com.palantir.atlasdb.table.description.ColumnMetadataDescription) JsonNode(com.fasterxml.jackson.databind.JsonNode) NamedColumnDescription(com.palantir.atlasdb.table.description.NamedColumnDescription)

Example 8 with ColumnMetadataDescription

use of com.palantir.atlasdb.table.description.ColumnMetadataDescription in project atlasdb by palantir.

the class TableCellSerializer method serialize.

private static void serialize(JsonGenerator jgen, TableMetadata metadata, Cell cell) throws IOException {
    byte[] row = cell.getRowName();
    byte[] col = cell.getColumnName();
    jgen.writeStartObject();
    AtlasSerializers.serializeRow(jgen, metadata.getRowMetadata(), row);
    ColumnMetadataDescription columns = metadata.getColumns();
    if (columns.hasDynamicColumns()) {
        DynamicColumnDescription dynamicColumn = columns.getDynamicColumn();
        AtlasSerializers.serializeDynamicColumn(jgen, dynamicColumn, col);
    } else {
        String shortName = PtBytes.toString(col);
        jgen.writeStringField("col", getLongColumnName(columns, shortName));
    }
    jgen.writeEndObject();
}
Also used : ColumnMetadataDescription(com.palantir.atlasdb.table.description.ColumnMetadataDescription) DynamicColumnDescription(com.palantir.atlasdb.table.description.DynamicColumnDescription)

Example 9 with ColumnMetadataDescription

use of com.palantir.atlasdb.table.description.ColumnMetadataDescription in project atlasdb by palantir.

the class TableMetadataDeserializer method deserializeDynamicCol.

private ColumnMetadataDescription deserializeDynamicCol(JsonNode node) {
    NameMetadataDescription col = deserializeRowish(node.get("column"));
    ColumnValueDescription val = deserializeValue(node.get("value"));
    DynamicColumnDescription dynamicCol = new DynamicColumnDescription(col, val);
    return new ColumnMetadataDescription(dynamicCol);
}
Also used : NameMetadataDescription(com.palantir.atlasdb.table.description.NameMetadataDescription) ColumnMetadataDescription(com.palantir.atlasdb.table.description.ColumnMetadataDescription) DynamicColumnDescription(com.palantir.atlasdb.table.description.DynamicColumnDescription) ColumnValueDescription(com.palantir.atlasdb.table.description.ColumnValueDescription)

Example 10 with ColumnMetadataDescription

use of com.palantir.atlasdb.table.description.ColumnMetadataDescription in project atlasdb by palantir.

the class TableCellValSerializer method serialize.

private static void serialize(JsonGenerator jgen, TableMetadata metadata, Entry<Cell, byte[]> result) throws IOException {
    Cell cell = result.getKey();
    byte[] row = cell.getRowName();
    byte[] col = cell.getColumnName();
    byte[] val = result.getValue();
    jgen.writeStartObject();
    AtlasSerializers.serializeRow(jgen, metadata.getRowMetadata(), row);
    ColumnMetadataDescription columns = metadata.getColumns();
    if (columns.hasDynamicColumns()) {
        DynamicColumnDescription dynamicColumn = columns.getDynamicColumn();
        AtlasSerializers.serializeDynamicColumn(jgen, dynamicColumn, col);
        jgen.writeFieldName("val");
        AtlasSerializers.serializeVal(jgen, dynamicColumn.getValue(), val);
    } else {
        String shortName = PtBytes.toString(col);
        Set<NamedColumnDescription> namedColumns = columns.getNamedColumns();
        for (NamedColumnDescription description : namedColumns) {
            if (shortName.equals(description.getShortName())) {
                AtlasSerializers.serializeNamedCol(jgen, description, val);
                break;
            }
        }
    }
    jgen.writeEndObject();
}
Also used : ColumnMetadataDescription(com.palantir.atlasdb.table.description.ColumnMetadataDescription) DynamicColumnDescription(com.palantir.atlasdb.table.description.DynamicColumnDescription) NamedColumnDescription(com.palantir.atlasdb.table.description.NamedColumnDescription) Cell(com.palantir.atlasdb.keyvalue.api.Cell)

Aggregations

ColumnMetadataDescription (com.palantir.atlasdb.table.description.ColumnMetadataDescription)13 NameMetadataDescription (com.palantir.atlasdb.table.description.NameMetadataDescription)7 DynamicColumnDescription (com.palantir.atlasdb.table.description.DynamicColumnDescription)6 NamedColumnDescription (com.palantir.atlasdb.table.description.NamedColumnDescription)6 TableMetadata (com.palantir.atlasdb.table.description.TableMetadata)6 JsonNode (com.fasterxml.jackson.databind.JsonNode)3 ColumnValueDescription (com.palantir.atlasdb.table.description.ColumnValueDescription)2 Test (org.junit.Test)2 Cell (com.palantir.atlasdb.keyvalue.api.Cell)1 TableReference (com.palantir.atlasdb.keyvalue.api.TableReference)1 InMemoryTimestampService (com.palantir.timestamp.InMemoryTimestampService)1 ArrayList (java.util.ArrayList)1 Entry (java.util.Map.Entry)1 Before (org.junit.Before)1