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);
}
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()));
}
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;
}
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;
}
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;
}
Aggregations