Search in sources :

Example 71 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 72 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 73 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)

Example 74 with ColumnMetadata

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

the class CollectionEntryIndex method isStale.

public boolean isStale(Row data, ByteBuffer indexValue, int nowInSec) {
    ByteBuffer[] components = ((CompositeType) functions.getIndexedValueType(indexedColumn)).split(indexValue);
    ByteBuffer mapKey = components[0];
    ByteBuffer mapValue = components[1];
    ColumnMetadata columnDef = indexedColumn;
    Cell cell = data.getCell(columnDef, CellPath.create(mapKey));
    if (cell == null || !cell.isLive(nowInSec))
        return true;
    AbstractType<?> valueComparator = ((CollectionType) columnDef.type).valueComparator();
    return valueComparator.compare(mapValue, cell.value()) != 0;
}
Also used : ColumnMetadata(org.apache.cassandra.schema.ColumnMetadata) CollectionType(org.apache.cassandra.db.marshal.CollectionType) ByteBuffer(java.nio.ByteBuffer) Cell(org.apache.cassandra.db.rows.Cell) CompositeType(org.apache.cassandra.db.marshal.CompositeType)

Example 75 with ColumnMetadata

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

the class CollectionValueIndex method isStale.

public boolean isStale(Row data, ByteBuffer indexValue, int nowInSec) {
    ColumnMetadata columnDef = indexedColumn;
    ComplexColumnData complexData = data.getComplexColumnData(columnDef);
    if (complexData == null)
        return true;
    for (Cell cell : complexData) {
        if (cell.isLive(nowInSec) && ((CollectionType) columnDef.type).valueComparator().compare(indexValue, cell.value()) == 0)
            return false;
    }
    return true;
}
Also used : ColumnMetadata(org.apache.cassandra.schema.ColumnMetadata)

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