Search in sources :

Example 6 with NamedColumnDescription

use of com.palantir.atlasdb.table.description.NamedColumnDescription 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 NamedColumnDescription

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

the class AtlasDeserializers method deserializeNamedCol.

private static byte[] deserializeNamedCol(ColumnMetadataDescription colDescription, JsonNode node) {
    JsonNode nonArrayNode = node;
    if (nonArrayNode.isArray()) {
        nonArrayNode = node.get(0);
    }
    NamedColumnDescription namedCol = getNamedCol(colDescription, nonArrayNode.textValue());
    return PtBytes.toCachedBytes(namedCol.getShortName());
}
Also used : JsonNode(com.fasterxml.jackson.databind.JsonNode) NamedColumnDescription(com.palantir.atlasdb.table.description.NamedColumnDescription)

Example 8 with NamedColumnDescription

use of com.palantir.atlasdb.table.description.NamedColumnDescription 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 9 with NamedColumnDescription

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

the class AtlasSerializers method serializeCol.

public static void serializeCol(JsonGenerator jgen, ColumnMetadataDescription colDescription, byte[] col) throws IOException {
    if (colDescription.hasDynamicColumns()) {
        DynamicColumnDescription dynMetadata = colDescription.getDynamicColumn();
        NameMetadataDescription description = dynMetadata.getColumnNameDesc();
        jgen.writeRawValue(description.renderToJson(col));
    } else {
        Set<NamedColumnDescription> namedColumns = colDescription.getNamedColumns();
        for (NamedColumnDescription description : namedColumns) {
            if (UnsignedBytes.lexicographicalComparator().compare(col, PtBytes.toCachedBytes(description.getShortName())) == 0) {
                jgen.writeString(description.getLongName());
                return;
            }
        }
        throw new IllegalArgumentException("Column " + BaseEncoding.base16().lowerCase().encode(col) + " is not a valid column.");
    }
}
Also used : NameMetadataDescription(com.palantir.atlasdb.table.description.NameMetadataDescription) DynamicColumnDescription(com.palantir.atlasdb.table.description.DynamicColumnDescription) NamedColumnDescription(com.palantir.atlasdb.table.description.NamedColumnDescription)

Example 10 with NamedColumnDescription

use of com.palantir.atlasdb.table.description.NamedColumnDescription 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

NamedColumnDescription (com.palantir.atlasdb.table.description.NamedColumnDescription)13 ColumnMetadataDescription (com.palantir.atlasdb.table.description.ColumnMetadataDescription)6 JsonNode (com.fasterxml.jackson.databind.JsonNode)4 DynamicColumnDescription (com.palantir.atlasdb.table.description.DynamicColumnDescription)4 MethodSpec (com.squareup.javapoet.MethodSpec)4 ArrayList (java.util.ArrayList)4 NameMetadataDescription (com.palantir.atlasdb.table.description.NameMetadataDescription)3 TableMetadata (com.palantir.atlasdb.table.description.TableMetadata)2 ImmutableSortedMap (com.google.common.collect.ImmutableSortedMap)1 TableRowResult (com.palantir.atlasdb.api.TableRowResult)1 Cell (com.palantir.atlasdb.keyvalue.api.Cell)1 RowResult (com.palantir.atlasdb.keyvalue.api.RowResult)1 TableReference (com.palantir.atlasdb.keyvalue.api.TableReference)1 ColumnValueDescription (com.palantir.atlasdb.table.description.ColumnValueDescription)1 Persistables (com.palantir.common.persist.Persistables)1 Entry (java.util.Map.Entry)1