Search in sources :

Example 6 with TableMetadata

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

the class TableCellDeserializer method deserialize.

@Override
public TableCell deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException {
    JsonNode node = jp.readValueAsTree();
    String tableName = node.get("table").textValue();
    TableMetadata metadata = metadataCache.getMetadata(tableName);
    Iterable<Cell> cells = AtlasDeserializers.deserializeCells(metadata, node.get("data"));
    return new TableCell(tableName, cells);
}
Also used : TableMetadata(com.palantir.atlasdb.table.description.TableMetadata) TableCell(com.palantir.atlasdb.api.TableCell) JsonNode(com.fasterxml.jackson.databind.JsonNode) Cell(com.palantir.atlasdb.keyvalue.api.Cell) TableCell(com.palantir.atlasdb.api.TableCell)

Example 7 with TableMetadata

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

the class TableCellSerializer method serialize.

@Override
public void serialize(TableCell value, JsonGenerator jgen, SerializerProvider provider) throws IOException {
    TableMetadata metadata = metadataCache.getMetadata(value.getTableName());
    Preconditions.checkNotNull(metadata, "Unknown table %s", value.getTableName());
    jgen.writeStartObject();
    jgen.writeStringField("table", value.getTableName());
    jgen.writeArrayFieldStart("data");
    for (Cell cell : value.getCells()) {
        serialize(jgen, metadata, cell);
    }
    jgen.writeEndArray();
    jgen.writeEndObject();
}
Also used : TableMetadata(com.palantir.atlasdb.table.description.TableMetadata) Cell(com.palantir.atlasdb.keyvalue.api.Cell) TableCell(com.palantir.atlasdb.api.TableCell)

Example 8 with TableMetadata

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

the class TableMetadataDeserializer method deserialize.

@Override
public TableMetadata deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException {
    JsonNode node = jp.readValueAsTree();
    NameMetadataDescription row = deserializeRowish(node);
    ColumnMetadataDescription col;
    if (node.get("is_dynamic").asBoolean()) {
        col = deserializeDynamicCol(node);
    } else {
        col = deserializeNamedCols(node);
    }
    return new TableMetadata(row, col, ConflictHandler.IGNORE_ALL);
}
Also used : TableMetadata(com.palantir.atlasdb.table.description.TableMetadata) NameMetadataDescription(com.palantir.atlasdb.table.description.NameMetadataDescription) ColumnMetadataDescription(com.palantir.atlasdb.table.description.ColumnMetadataDescription) JsonNode(com.fasterxml.jackson.databind.JsonNode)

Example 9 with TableMetadata

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

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

the class TableRangeSerializer method serialize.

@Override
public void serialize(TableRange value, JsonGenerator jgen, SerializerProvider provider) throws IOException {
    TableMetadata metadata = metadataCache.getMetadata(value.getTableName());
    jgen.writeStartObject();
    jgen.writeStringField("table", value.getTableName());
    jgen.writeBinaryField("raw_start", value.getStartRow());
    jgen.writeBinaryField("raw_end", value.getEndRow());
    jgen.writeNumberField("batch_size", value.getBatchSize());
    if (!Iterables.isEmpty(value.getColumns())) {
        jgen.writeArrayFieldStart("cols");
        for (byte[] column : value.getColumns()) {
            AtlasSerializers.serializeCol(jgen, metadata.getColumns(), column);
        }
        jgen.writeEndArray();
    }
    jgen.writeEndObject();
}
Also used : TableMetadata(com.palantir.atlasdb.table.description.TableMetadata)

Aggregations

TableMetadata (com.palantir.atlasdb.table.description.TableMetadata)26 JsonNode (com.fasterxml.jackson.databind.JsonNode)6 ColumnMetadataDescription (com.palantir.atlasdb.table.description.ColumnMetadataDescription)6 NameMetadataDescription (com.palantir.atlasdb.table.description.NameMetadataDescription)5 Test (org.junit.Test)5 Cell (com.palantir.atlasdb.keyvalue.api.Cell)4 BoundStatement (com.datastax.driver.core.BoundStatement)2 TableCell (com.palantir.atlasdb.api.TableCell)2 NamedColumnDescription (com.palantir.atlasdb.table.description.NamedColumnDescription)2 ResultSet (com.datastax.driver.core.ResultSet)1 ImmutableSortedMap (com.google.common.collect.ImmutableSortedMap)1 TableCellVal (com.palantir.atlasdb.api.TableCellVal)1 TableRange (com.palantir.atlasdb.api.TableRange)1 TableRowResult (com.palantir.atlasdb.api.TableRowResult)1 TableRowSelection (com.palantir.atlasdb.api.TableRowSelection)1 RowResult (com.palantir.atlasdb.keyvalue.api.RowResult)1 TableReference (com.palantir.atlasdb.keyvalue.api.TableReference)1 TableMetadataPersistence (com.palantir.atlasdb.protos.generated.TableMetadataPersistence)1 DynamicColumnDescription (com.palantir.atlasdb.table.description.DynamicColumnDescription)1 TableDefinition (com.palantir.atlasdb.table.description.TableDefinition)1