use of com.palantir.atlasdb.table.description.ColumnMetadataDescription 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.ColumnMetadataDescription in project atlasdb by palantir.
the class AtlasDeserializers method deserializeCellVal.
private static Iterable<Entry<Cell, byte[]>> deserializeCellVal(TableMetadata metadata, JsonNode node) {
byte[] row = deserializeRow(metadata.getRowMetadata(), node.get("row"));
ColumnMetadataDescription colDescription = metadata.getColumns();
if (colDescription.hasDynamicColumns()) {
byte[] col = deserializeDynamicCol(colDescription.getDynamicColumn(), node.get("col"));
byte[] val = deserializeVal(colDescription.getDynamicColumn().getValue(), node.get("val"));
return ImmutableList.of(Maps.immutableEntry(Cell.create(row, col), val));
} else {
Collection<Entry<Cell, byte[]>> results = Lists.newArrayListWithCapacity(1);
Iterator<Entry<String, JsonNode>> fields = node.fields();
while (fields.hasNext()) {
Entry<String, JsonNode> entry = fields.next();
String longName = entry.getKey();
if (longName.equals("row")) {
continue;
}
NamedColumnDescription description = getNamedCol(colDescription, longName);
byte[] col = PtBytes.toCachedBytes(description.getShortName());
JsonNode valNode = entry.getValue();
byte[] val = deserializeVal(description.getValue(), valNode);
results.add(Maps.immutableEntry(Cell.create(row, col), val));
}
return results;
}
}
use of com.palantir.atlasdb.table.description.ColumnMetadataDescription 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();
}
use of com.palantir.atlasdb.table.description.ColumnMetadataDescription in project atlasdb by palantir.
the class TableMetadataDeserializer method deserializeDynamicCol.
private ColumnMetadataDescription deserializeDynamicCol(JsonNode node) {
NameMetadataDescription col = deserializeRowish(node.get("column"));
ColumnValueDescription val = deserializeValue(node.get("value"));
DynamicColumnDescription dynamicCol = new DynamicColumnDescription(col, val);
return new ColumnMetadataDescription(dynamicCol);
}
use of com.palantir.atlasdb.table.description.ColumnMetadataDescription in project atlasdb by palantir.
the class TableCellValSerializer method serialize.
private static void serialize(JsonGenerator jgen, TableMetadata metadata, Entry<Cell, byte[]> result) throws IOException {
Cell cell = result.getKey();
byte[] row = cell.getRowName();
byte[] col = cell.getColumnName();
byte[] val = result.getValue();
jgen.writeStartObject();
AtlasSerializers.serializeRow(jgen, metadata.getRowMetadata(), row);
ColumnMetadataDescription columns = metadata.getColumns();
if (columns.hasDynamicColumns()) {
DynamicColumnDescription dynamicColumn = columns.getDynamicColumn();
AtlasSerializers.serializeDynamicColumn(jgen, dynamicColumn, col);
jgen.writeFieldName("val");
AtlasSerializers.serializeVal(jgen, dynamicColumn.getValue(), val);
} else {
String shortName = PtBytes.toString(col);
Set<NamedColumnDescription> namedColumns = columns.getNamedColumns();
for (NamedColumnDescription description : namedColumns) {
if (shortName.equals(description.getShortName())) {
AtlasSerializers.serializeNamedCol(jgen, description, val);
break;
}
}
}
jgen.writeEndObject();
}
Aggregations