Search in sources :

Example 1 with TableMetadata

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

the class OracleDdlTable method create.

@Override
public void create(byte[] tableMetadata) {
    if (conns.get().selectExistsUnregisteredQuery("SELECT 1 FROM " + config.metadataTable().getQualifiedName() + " WHERE table_name = ?", tableRef.getQualifiedName())) {
        return;
    }
    boolean needsOverflow = false;
    TableMetadata metadata = TableMetadata.BYTES_HYDRATOR.hydrateFromBytes(tableMetadata);
    if (metadata != null) {
        needsOverflow = metadata.getColumns().getMaxValueSize() > AtlasDbConstants.ORACLE_OVERFLOW_THRESHOLD;
    }
    createTable(needsOverflow);
    if (needsOverflow && config.overflowMigrationState() != OverflowMigrationState.UNSTARTED) {
        createOverflowTable();
    }
    conns.get().insertOneUnregisteredQuery("INSERT INTO " + config.metadataTable().getQualifiedName() + " (table_name, table_size) VALUES (?, ?)", tableRef.getQualifiedName(), needsOverflow ? TableValueStyle.OVERFLOW.getId() : TableValueStyle.RAW.getId());
}
Also used : TableMetadata(com.palantir.atlasdb.table.description.TableMetadata)

Example 2 with TableMetadata

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

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

the class TableRowSelectionSerializer method serialize.

@Override
public void serialize(TableRowSelection value, JsonGenerator jgen, SerializerProvider provider) throws IOException {
    TableMetadata metadata = metadataCache.getMetadata(value.getTableName());
    Preconditions.checkNotNull(metadata, "Unknown table %s", value.getTableName());
    jgen.writeStartObject();
    jgen.writeStringField("table", value.getTableName());
    jgen.writeArrayFieldStart("rows");
    for (byte[] row : value.getRows()) {
        AtlasSerializers.serializeRowish(jgen, metadata.getRowMetadata(), row);
    }
    jgen.writeEndArray();
    if (!value.getColumnSelection().allColumnsSelected()) {
        jgen.writeArrayFieldStart("cols");
        for (byte[] col : value.getColumnSelection().getSelectedColumns()) {
            jgen.writeUTF8String(col, 0, col.length);
        }
        jgen.writeEndArray();
    }
    jgen.writeEndObject();
}
Also used : TableMetadata(com.palantir.atlasdb.table.description.TableMetadata)

Example 4 with TableMetadata

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

the class TableRowSelectionDeserializer method deserialize.

@Override
public TableRowSelection deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException {
    JsonNode node = jp.readValueAsTree();
    String tableName = node.get("table").textValue();
    TableMetadata metadata = metadataCache.getMetadata(tableName);
    Iterable<byte[]> rows = AtlasDeserializers.deserializeRows(metadata.getRowMetadata(), node.get("rows"));
    Iterable<byte[]> columns = AtlasDeserializers.deserializeNamedCols(metadata.getColumns(), node.get("cols"));
    if (Iterables.isEmpty(columns)) {
        return new TableRowSelection(tableName, rows, ColumnSelection.all());
    } else {
        return new TableRowSelection(tableName, rows, ColumnSelection.create(columns));
    }
}
Also used : TableMetadata(com.palantir.atlasdb.table.description.TableMetadata) TableRowSelection(com.palantir.atlasdb.api.TableRowSelection) JsonNode(com.fasterxml.jackson.databind.JsonNode)

Example 5 with TableMetadata

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

Aggregations

TableMetadata (com.palantir.atlasdb.table.description.TableMetadata)26 JsonNode (com.fasterxml.jackson.databind.JsonNode)6 ColumnMetadataDescription (com.palantir.atlasdb.table.description.ColumnMetadataDescription)6 NameMetadataDescription (com.palantir.atlasdb.table.description.NameMetadataDescription)5 Test (org.junit.Test)5 Cell (com.palantir.atlasdb.keyvalue.api.Cell)4 BoundStatement (com.datastax.driver.core.BoundStatement)2 TableCell (com.palantir.atlasdb.api.TableCell)2 NamedColumnDescription (com.palantir.atlasdb.table.description.NamedColumnDescription)2 ResultSet (com.datastax.driver.core.ResultSet)1 ImmutableSortedMap (com.google.common.collect.ImmutableSortedMap)1 TableCellVal (com.palantir.atlasdb.api.TableCellVal)1 TableRange (com.palantir.atlasdb.api.TableRange)1 TableRowResult (com.palantir.atlasdb.api.TableRowResult)1 TableRowSelection (com.palantir.atlasdb.api.TableRowSelection)1 RowResult (com.palantir.atlasdb.keyvalue.api.RowResult)1 TableReference (com.palantir.atlasdb.keyvalue.api.TableReference)1 TableMetadataPersistence (com.palantir.atlasdb.protos.generated.TableMetadataPersistence)1 DynamicColumnDescription (com.palantir.atlasdb.table.description.DynamicColumnDescription)1 TableDefinition (com.palantir.atlasdb.table.description.TableDefinition)1