Search in sources :

Example 1 with DynamicColumnDescription

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

the class KeyValueServiceScrubberStore method tryInitialize.

private void tryInitialize() {
    TableMetadata scrubTableMeta = new TableMetadata(NameMetadataDescription.create(ImmutableList.of(new NameComponentDescription.Builder().componentName("row").type(ValueType.BLOB).build())), new ColumnMetadataDescription(new DynamicColumnDescription(NameMetadataDescription.create(ImmutableList.of(new NameComponentDescription.Builder().componentName("table").type(ValueType.VAR_STRING).build(), new NameComponentDescription.Builder().componentName("col").type(ValueType.BLOB).build())), ColumnValueDescription.forType(ValueType.VAR_LONG))), ConflictHandler.IGNORE_ALL, TableMetadataPersistence.LogSafety.SAFE);
    keyValueService.createTable(AtlasDbConstants.SCRUB_TABLE, scrubTableMeta.persistToBytes());
}
Also used : TableMetadata(com.palantir.atlasdb.table.description.TableMetadata) ColumnMetadataDescription(com.palantir.atlasdb.table.description.ColumnMetadataDescription) DynamicColumnDescription(com.palantir.atlasdb.table.description.DynamicColumnDescription)

Example 2 with DynamicColumnDescription

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

Example 3 with DynamicColumnDescription

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

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

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

Aggregations

DynamicColumnDescription (com.palantir.atlasdb.table.description.DynamicColumnDescription)7 ColumnMetadataDescription (com.palantir.atlasdb.table.description.ColumnMetadataDescription)6 NamedColumnDescription (com.palantir.atlasdb.table.description.NamedColumnDescription)4 NameMetadataDescription (com.palantir.atlasdb.table.description.NameMetadataDescription)3 Cell (com.palantir.atlasdb.keyvalue.api.Cell)1 ColumnValueDescription (com.palantir.atlasdb.table.description.ColumnValueDescription)1 TableMetadata (com.palantir.atlasdb.table.description.TableMetadata)1