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());
}
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();
}
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();
}
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.");
}
}
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();
}
Aggregations