Search in sources :

Example 1 with NameMetadataDescription

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

the class Renderers method getRowComponents.

public static List<NameComponentDescription> getRowComponents(TableMetadata tableMetadata) {
    NameMetadataDescription rowMetadata = tableMetadata.getRowMetadata();
    List<NameComponentDescription> rowParts = rowMetadata.getRowParts();
    return rowMetadata.numberOfComponentsHashed() == 0 ? rowParts : rowParts.subList(1, rowParts.size());
}
Also used : NameComponentDescription(com.palantir.atlasdb.table.description.NameComponentDescription) NameMetadataDescription(com.palantir.atlasdb.table.description.NameMetadataDescription)

Example 2 with NameMetadataDescription

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

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

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

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

Aggregations

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