use of com.palantir.atlasdb.table.description.NamedColumnDescription 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.NamedColumnDescription in project atlasdb by palantir.
the class AtlasDeserializers method deserializeNamedCol.
private static byte[] deserializeNamedCol(ColumnMetadataDescription colDescription, JsonNode node) {
JsonNode nonArrayNode = node;
if (nonArrayNode.isArray()) {
nonArrayNode = node.get(0);
}
NamedColumnDescription namedCol = getNamedCol(colDescription, nonArrayNode.textValue());
return PtBytes.toCachedBytes(namedCol.getShortName());
}
use of com.palantir.atlasdb.table.description.NamedColumnDescription 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.NamedColumnDescription 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.NamedColumnDescription 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