Search in sources :

Example 96 with ColumnMetadata

use of org.apache.cassandra.schema.ColumnMetadata in project cassandra by apache.

the class SerializationHeader method toComponent.

public Component toComponent() {
    Map<ByteBuffer, AbstractType<?>> staticColumns = new LinkedHashMap<>();
    Map<ByteBuffer, AbstractType<?>> regularColumns = new LinkedHashMap<>();
    for (ColumnMetadata column : columns.statics) staticColumns.put(column.name.bytes, column.type);
    for (ColumnMetadata column : columns.regulars) regularColumns.put(column.name.bytes, column.type);
    return new Component(keyType, clusteringTypes, staticColumns, regularColumns, stats);
}
Also used : ColumnMetadata(org.apache.cassandra.schema.ColumnMetadata) AbstractType(org.apache.cassandra.db.marshal.AbstractType) MetadataComponent(org.apache.cassandra.io.sstable.metadata.MetadataComponent) ByteBuffer(java.nio.ByteBuffer)

Example 97 with ColumnMetadata

use of org.apache.cassandra.schema.ColumnMetadata in project cassandra by apache.

the class Clustering method toCQLString.

public default default String toCQLString(TableMetadata metadata) {
    StringBuilder sb = new StringBuilder();
    for (int i = 0; i < size(); i++) {
        ColumnMetadata c = metadata.clusteringColumns().get(i);
        sb.append(i == 0 ? "" : ", ").append(c.type.getString(get(i)));
    }
    return sb.toString();
}
Also used : ColumnMetadata(org.apache.cassandra.schema.ColumnMetadata)

Example 98 with ColumnMetadata

use of org.apache.cassandra.schema.ColumnMetadata in project cassandra by apache.

the class Clustering method toString.

public default default String toString(TableMetadata metadata) {
    StringBuilder sb = new StringBuilder();
    for (int i = 0; i < size(); i++) {
        ColumnMetadata c = metadata.clusteringColumns().get(i);
        sb.append(i == 0 ? "" : ", ").append(c.name).append('=').append(get(i) == null ? "null" : c.type.getString(get(i)));
    }
    return sb.toString();
}
Also used : ColumnMetadata(org.apache.cassandra.schema.ColumnMetadata)

Example 99 with ColumnMetadata

use of org.apache.cassandra.schema.ColumnMetadata in project cassandra by apache.

the class TargetParser method parse.

public static Pair<ColumnMetadata, IndexTarget.Type> parse(TableMetadata metadata, String target) {
    // if the regex matches then the target is in the form "keys(foo)", "entries(bar)" etc
    // if not, then it must be a simple column name and implictly its type is VALUES
    Matcher matcher = TARGET_REGEX.matcher(target);
    String columnName;
    IndexTarget.Type targetType;
    if (matcher.matches()) {
        targetType = IndexTarget.Type.fromString(matcher.group(1));
        columnName = matcher.group(2);
    } else {
        columnName = target;
        targetType = IndexTarget.Type.VALUES;
    }
    // need to un-escape any such quotes to get the actual column name
    if (columnName.startsWith(QUOTE)) {
        columnName = StringUtils.substring(StringUtils.substring(columnName, 1), 0, -1);
        columnName = TWO_QUOTES.matcher(columnName).replaceAll(QUOTE);
    }
    // in that case we have to do a linear scan of the table's columns to get the matching one
    if (metadata.isCQLTable())
        return Pair.create(metadata.getColumn(new ColumnIdentifier(columnName, true)), targetType);
    else
        for (ColumnMetadata column : metadata.columns()) if (column.name.toString().equals(columnName))
            return Pair.create(column, targetType);
    return null;
}
Also used : ColumnMetadata(org.apache.cassandra.schema.ColumnMetadata) Matcher(java.util.regex.Matcher) IndexTarget(org.apache.cassandra.cql3.statements.IndexTarget) ColumnIdentifier(org.apache.cassandra.cql3.ColumnIdentifier)

Example 100 with ColumnMetadata

use of org.apache.cassandra.schema.ColumnMetadata in project cassandra by apache.

the class CassandraIndex method indexCfsMetadata.

/**
     * Construct the TableMetadata for an index table, the clustering columns in the index table
     * vary dependent on the kind of the indexed value.
     * @param baseCfsMetadata
     * @param indexMetadata
     * @return
     */
public static TableMetadata indexCfsMetadata(TableMetadata baseCfsMetadata, IndexMetadata indexMetadata) {
    Pair<ColumnMetadata, IndexTarget.Type> target = TargetParser.parse(baseCfsMetadata, indexMetadata);
    CassandraIndexFunctions utils = getFunctions(indexMetadata, target);
    ColumnMetadata indexedColumn = target.left;
    AbstractType<?> indexedValueType = utils.getIndexedValueType(indexedColumn);
    TableMetadata.Builder builder = TableMetadata.builder(baseCfsMetadata.keyspace, baseCfsMetadata.indexTableName(indexMetadata), baseCfsMetadata.id).isDense(indexMetadata.isKeys()).isCompound(!indexMetadata.isKeys()).partitioner(new LocalPartitioner(indexedValueType)).addPartitionKeyColumn(indexedColumn.name, indexedColumn.type).addClusteringColumn("partition_key", baseCfsMetadata.partitioner.partitionOrdering());
    if (indexMetadata.isKeys()) {
        // A dense, compact table for KEYS indexes must have a compact
        // value column defined, even though it is never used
        CompactTables.DefaultNames names = CompactTables.defaultNameGenerator(ImmutableSet.of(indexedColumn.name.toString(), "partition_key"));
        builder.addRegularColumn(names.defaultCompactValueName(), EmptyType.instance);
    } else {
        // The clustering columns for a table backing a COMPOSITES index are dependent
        // on the specific type of index (there are specializations for indexes on collections)
        utils.addIndexClusteringColumns(builder, baseCfsMetadata, indexedColumn);
    }
    return builder.build().updateIndexTableMetadata(baseCfsMetadata.params);
}
Also used : TableMetadata(org.apache.cassandra.schema.TableMetadata) ColumnMetadata(org.apache.cassandra.schema.ColumnMetadata) AbstractType(org.apache.cassandra.db.marshal.AbstractType) CollectionType(org.apache.cassandra.db.marshal.CollectionType) EmptyType(org.apache.cassandra.db.marshal.EmptyType) LocalPartitioner(org.apache.cassandra.dht.LocalPartitioner)

Aggregations

ColumnMetadata (org.apache.cassandra.schema.ColumnMetadata)123 Test (org.junit.Test)35 ByteBuffer (java.nio.ByteBuffer)23 Row (org.apache.cassandra.db.rows.Row)17 TableMetadata (org.apache.cassandra.schema.TableMetadata)16 ColumnIdentifier (org.apache.cassandra.cql3.ColumnIdentifier)15 AbstractType (org.apache.cassandra.db.marshal.AbstractType)8 ConfigurationException (org.apache.cassandra.exceptions.ConfigurationException)5 java.util (java.util)4 IndexTarget (org.apache.cassandra.cql3.statements.IndexTarget)4 CollectionType (org.apache.cassandra.db.marshal.CollectionType)4 IndexMetadata (org.apache.cassandra.schema.IndexMetadata)4 IOException (java.io.IOException)3 Collectors (java.util.stream.Collectors)3 ColumnFamilyStore (org.apache.cassandra.db.ColumnFamilyStore)3 ColumnFilter (org.apache.cassandra.db.filter.ColumnFilter)3 ImmutableBTreePartition (org.apache.cassandra.db.partitions.ImmutableBTreePartition)3 Cell (org.apache.cassandra.db.rows.Cell)3 RowIterator (org.apache.cassandra.db.rows.RowIterator)3 InvalidRequestException (org.apache.cassandra.exceptions.InvalidRequestException)3