Search in sources :

Example 1 with NamedColumnDescription

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

the class TableClassRendererV2 method renderNamedPutAndUpdate.

private List<MethodSpec> renderNamedPutAndUpdate() {
    List<MethodSpec> putAndUpdateResults = new ArrayList<>();
    for (NamedColumnDescription col : ColumnRenderers.namedColumns(tableMetadata)) {
        putAndUpdateResults.add(renderNamedPutColumn(col));
        putAndUpdateResults.add(renderNamedUpdateColumn(col));
    }
    return putAndUpdateResults;
}
Also used : MethodSpec(com.squareup.javapoet.MethodSpec) ArrayList(java.util.ArrayList) NamedColumnDescription(com.palantir.atlasdb.table.description.NamedColumnDescription)

Example 2 with NamedColumnDescription

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

the class AbstractKeyValueServiceTest method createTableWithNamedColumns.

private TableReference createTableWithNamedColumns(int numColumns) {
    TableReference tableRef = TableReference.createFromFullyQualifiedName("ns.pt_kvs_test_named_cols_" + numColumns);
    List<NamedColumnDescription> columns = new ArrayList<>();
    for (int i = 1; i <= numColumns; ++i) {
        columns.add(new NamedColumnDescription("c" + i, "column" + i, ColumnValueDescription.forType(ValueType.BLOB)));
    }
    keyValueService.createTable(tableRef, new TableMetadata(new NameMetadataDescription(), new ColumnMetadataDescription(columns), ConflictHandler.RETRY_ON_WRITE_WRITE, TableMetadataPersistence.LogSafety.SAFE).persistToBytes());
    keyValueService.truncateTable(tableRef);
    return tableRef;
}
Also used : TableMetadata(com.palantir.atlasdb.table.description.TableMetadata) TableReference(com.palantir.atlasdb.keyvalue.api.TableReference) ArrayList(java.util.ArrayList) NameMetadataDescription(com.palantir.atlasdb.table.description.NameMetadataDescription) ColumnMetadataDescription(com.palantir.atlasdb.table.description.ColumnMetadataDescription) NamedColumnDescription(com.palantir.atlasdb.table.description.NamedColumnDescription)

Example 3 with NamedColumnDescription

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

the class TableMetadataDeserializer method deserializeNamedCols.

private ColumnMetadataDescription deserializeNamedCols(JsonNode node) {
    Collection<NamedColumnDescription> cols = Lists.newArrayList();
    for (JsonNode colNode : node.get("columns")) {
        String name = colNode.get("name").asText();
        String longName = colNode.get("long_name").asText();
        ColumnValueDescription val = deserializeValue(colNode.get("value"));
        cols.add(new NamedColumnDescription(name, longName, val));
    }
    return new ColumnMetadataDescription(cols);
}
Also used : ColumnMetadataDescription(com.palantir.atlasdb.table.description.ColumnMetadataDescription) JsonNode(com.fasterxml.jackson.databind.JsonNode) NamedColumnDescription(com.palantir.atlasdb.table.description.NamedColumnDescription) ColumnValueDescription(com.palantir.atlasdb.table.description.ColumnValueDescription)

Example 4 with NamedColumnDescription

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

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

the class TableMetadataSerializer method serialize.

@Override
public void serialize(TableMetadata value, JsonGenerator jgen, SerializerProvider provider) throws IOException {
    jgen.writeStartObject();
    NameMetadataDescription rowMetadata = value.getRowMetadata();
    ColumnMetadataDescription columnMetadata = value.getColumns();
    boolean isDynamic = columnMetadata.hasDynamicColumns();
    jgen.writeBooleanField("is_dynamic", isDynamic);
    jgen.writeArrayFieldStart("row");
    serialize(jgen, rowMetadata);
    jgen.writeEndArray();
    if (isDynamic) {
        DynamicColumnDescription dynamicColumn = columnMetadata.getDynamicColumn();
        jgen.writeArrayFieldStart("column");
        serialize(jgen, dynamicColumn.getColumnNameDesc());
        jgen.writeEndArray();
        jgen.writeObjectFieldStart("value");
        serialize(jgen, dynamicColumn.getValue());
        jgen.writeEndObject();
    } else {
        jgen.writeArrayFieldStart("columns");
        for (NamedColumnDescription namedColumn : columnMetadata.getNamedColumns()) {
            jgen.writeStartObject();
            jgen.writeObjectField("name", namedColumn.getShortName());
            jgen.writeObjectField("long_name", namedColumn.getLongName());
            jgen.writeObjectFieldStart("value");
            serialize(jgen, namedColumn.getValue());
            jgen.writeEndObject();
            jgen.writeEndObject();
        }
        jgen.writeEndArray();
    }
    jgen.writeEndObject();
}
Also used : NameMetadataDescription(com.palantir.atlasdb.table.description.NameMetadataDescription) ColumnMetadataDescription(com.palantir.atlasdb.table.description.ColumnMetadataDescription) DynamicColumnDescription(com.palantir.atlasdb.table.description.DynamicColumnDescription) NamedColumnDescription(com.palantir.atlasdb.table.description.NamedColumnDescription)

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