Search in sources :

Example 46 with ColumnMetadata

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

the class SingleColumnRelation method newContainsRestriction.

@Override
protected Restriction newContainsRestriction(TableMetadata table, VariableSpecifications boundNames, boolean isKey) throws InvalidRequestException {
    ColumnMetadata columnDef = entity.prepare(table);
    Term term = toTerm(toReceivers(columnDef), value, table.keyspace, boundNames);
    return new SingleColumnRestriction.ContainsRestriction(columnDef, term, isKey);
}
Also used : ColumnMetadata(org.apache.cassandra.schema.ColumnMetadata)

Example 47 with ColumnMetadata

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

the class TokenRelation method toReceivers.

/**
     * Returns the receivers for this relation.
     *
     * @param table the table meta data
     * @param columnDefs the column definitions
     * @return the receivers for the specified relation.
     * @throws InvalidRequestException if the relation is invalid
     */
private static List<? extends ColumnSpecification> toReceivers(TableMetadata table, List<ColumnMetadata> columnDefs) throws InvalidRequestException {
    if (!columnDefs.equals(table.partitionKeyColumns())) {
        checkTrue(columnDefs.containsAll(table.partitionKeyColumns()), "The token() function must be applied to all partition key components or none of them");
        checkContainsNoDuplicates(columnDefs, "The token() function contains duplicate partition key components");
        checkContainsOnly(columnDefs, table.partitionKeyColumns(), "The token() function must contains only partition key components");
        throw invalidRequest("The token function arguments must be in the partition key order: %s", Joiner.on(", ").join(ColumnMetadata.toIdentifiers(table.partitionKeyColumns())));
    }
    ColumnMetadata firstColumn = columnDefs.get(0);
    return Collections.singletonList(new ColumnSpecification(firstColumn.ksName, firstColumn.cfName, new ColumnIdentifier("partition key token", true), table.partitioner.getTokenValidator()));
}
Also used : ColumnMetadata(org.apache.cassandra.schema.ColumnMetadata)

Example 48 with ColumnMetadata

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

the class VariableSpecifications method getPartitionKeyBindIndexes.

/**
     * Returns an array with the same length as the number of partition key columns for the table corresponding
     * to table.  Each short in the array represents the bind index of the marker that holds the value for that
     * partition key column.  If there are no bind markers for any of the partition key columns, null is returned.
     *
     * Callers of this method should ensure that all statements operate on the same table.
     */
public short[] getPartitionKeyBindIndexes(TableMetadata metadata) {
    short[] partitionKeyPositions = new short[metadata.partitionKeyColumns().size()];
    boolean[] set = new boolean[partitionKeyPositions.length];
    for (int i = 0; i < targetColumns.length; i++) {
        ColumnMetadata targetColumn = targetColumns[i];
        if (targetColumn != null && targetColumn.isPartitionKey()) {
            assert targetColumn.ksName.equals(metadata.keyspace) && targetColumn.cfName.equals(metadata.name);
            partitionKeyPositions[targetColumn.position()] = (short) i;
            set[targetColumn.position()] = true;
        }
    }
    for (boolean b : set) if (!b)
        return null;
    return partitionKeyPositions;
}
Also used : ColumnMetadata(org.apache.cassandra.schema.ColumnMetadata)

Example 49 with ColumnMetadata

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

the class CreateViewStatement method getColumnIdentifier.

private static boolean getColumnIdentifier(TableMetadata cfm, Set<ColumnIdentifier> basePK, boolean hasNonPKColumn, ColumnMetadata.Raw raw, List<ColumnIdentifier> columns, StatementRestrictions restrictions) {
    ColumnMetadata def = raw.prepare(cfm);
    boolean isPk = basePK.contains(def.name);
    if (!isPk && hasNonPKColumn)
        throw new InvalidRequestException(String.format("Cannot include more than one non-primary key column '%s' in materialized view primary key", def.name));
    // We don't need to include the "IS NOT NULL" filter on a non-composite partition key
    // because we will never allow a single partition key to be NULL
    boolean isSinglePartitionKey = def.isPartitionKey() && cfm.partitionKeyColumns().size() == 1;
    if (!isSinglePartitionKey && !restrictions.isRestricted(def))
        throw new InvalidRequestException(String.format("Primary key column '%s' is required to be filtered by 'IS NOT NULL'", def.name));
    columns.add(def.name);
    return !isPk;
}
Also used : ColumnMetadata(org.apache.cassandra.schema.ColumnMetadata) InvalidRequestException(org.apache.cassandra.exceptions.InvalidRequestException)

Example 50 with ColumnMetadata

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

the class AbstractReadCommandBuilder method filterOn.

public AbstractReadCommandBuilder filterOn(String column, Operator op, Object value) {
    ColumnMetadata def = cfs.metadata().getColumn(ColumnIdentifier.getInterned(column, true));
    assert def != null;
    AbstractType<?> type = def.type;
    if (op == Operator.CONTAINS)
        type = forValues(type);
    else if (op == Operator.CONTAINS_KEY)
        type = forKeys(type);
    this.filter.add(def, op, bb(value, type));
    return this;
}
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