use of org.apache.cassandra.exceptions.InvalidRequestException in project cassandra by apache.
the class DropFunctionStatement method announceMigration.
public Event.SchemaChange announceMigration(QueryState queryState, boolean isLocalOnly) throws RequestValidationException {
Function old = findFunction();
if (old == null) {
if (ifExists)
return null;
else
throw new InvalidRequestException(getMissingFunctionError());
}
KeyspaceMetadata ksm = Schema.instance.getKeyspaceMetadata(old.name().keyspace);
Collection<UDAggregate> referrers = ksm.functions.aggregatesUsingFunction(old);
if (!referrers.isEmpty())
throw new InvalidRequestException(String.format("Function '%s' still referenced by %s", old, referrers));
MigrationManager.announceFunctionDrop((UDFunction) old, isLocalOnly);
return new Event.SchemaChange(Event.SchemaChange.Change.DROPPED, Event.SchemaChange.Target.FUNCTION, old.name().keyspace, old.name().name, AbstractType.asCQLTypeStringList(old.argTypes()));
}
use of org.apache.cassandra.exceptions.InvalidRequestException in project cassandra by apache.
the class DropTableStatement method announceMigration.
public Event.SchemaChange announceMigration(QueryState queryState, boolean isLocalOnly) throws ConfigurationException {
try {
KeyspaceMetadata ksm = Schema.instance.getKeyspaceMetadata(keyspace());
if (ksm == null)
throw new ConfigurationException(String.format("Cannot drop table in unknown keyspace '%s'", keyspace()));
TableMetadata metadata = ksm.getTableOrViewNullable(columnFamily());
if (metadata != null) {
if (metadata.isView())
throw new InvalidRequestException("Cannot use DROP TABLE on Materialized View");
boolean rejectDrop = false;
StringBuilder messageBuilder = new StringBuilder();
for (ViewMetadata def : ksm.views) {
if (def.baseTableId.equals(metadata.id)) {
if (rejectDrop)
messageBuilder.append(',');
rejectDrop = true;
messageBuilder.append(def.name);
}
}
if (rejectDrop) {
throw new InvalidRequestException(String.format("Cannot drop table when materialized views still depend on it (%s.{%s})", keyspace(), messageBuilder.toString()));
}
}
MigrationManager.announceTableDrop(keyspace(), columnFamily(), isLocalOnly);
return new Event.SchemaChange(Event.SchemaChange.Change.DROPPED, Event.SchemaChange.Target.TABLE, keyspace(), columnFamily());
} catch (ConfigurationException e) {
if (ifExists)
return null;
throw e;
}
}
use of org.apache.cassandra.exceptions.InvalidRequestException in project cassandra by apache.
the class ToJsonFct method getInstance.
public static ToJsonFct getInstance(List<AbstractType<?>> argTypes) throws InvalidRequestException {
if (argTypes.size() != 1)
throw new InvalidRequestException(String.format("toJson() only accepts one argument (got %d)", argTypes.size()));
AbstractType<?> fromType = argTypes.get(0);
ToJsonFct func = instances.get(fromType);
if (func == null) {
func = new ToJsonFct(fromType);
instances.put(fromType, func);
}
return func;
}
use of org.apache.cassandra.exceptions.InvalidRequestException in project cassandra by apache.
the class StatementRestrictions method processPartitionKeyRestrictions.
private void processPartitionKeyRestrictions(boolean hasQueriableIndex, boolean allowFiltering, boolean forView) {
if (!type.allowPartitionKeyRanges()) {
checkFalse(partitionKeyRestrictions.isOnToken(), "The token function cannot be used in WHERE clauses for %s statements", type);
if (partitionKeyRestrictions.hasUnrestrictedPartitionKeyComponents(table))
throw invalidRequest("Some partition key parts are missing: %s", Joiner.on(", ").join(getPartitionKeyUnrestrictedComponents()));
// slice query
checkFalse(partitionKeyRestrictions.hasSlice(), "Only EQ and IN relation are supported on the partition key (unless you use the token() function)" + " for %s statements", type);
} else {
// If there are no partition restrictions or there's only token restriction, we have to set a key range
if (partitionKeyRestrictions.isOnToken())
isKeyRange = true;
if (partitionKeyRestrictions.isEmpty() && partitionKeyRestrictions.hasUnrestrictedPartitionKeyComponents(table)) {
isKeyRange = true;
usesSecondaryIndexing = hasQueriableIndex;
}
// components must have a EQ. Only the last partition key component can be in IN relation.
if (partitionKeyRestrictions.needFiltering(table)) {
if (!allowFiltering && !forView && !hasQueriableIndex && (partitionKeyRestrictions.hasUnrestrictedPartitionKeyComponents(table) || partitionKeyRestrictions.hasSlice()))
throw new InvalidRequestException(REQUIRES_ALLOW_FILTERING_MESSAGE);
if (partitionKeyRestrictions.hasIN())
throw new InvalidRequestException("IN restrictions are not supported when the query involves filtering");
isKeyRange = true;
usesSecondaryIndexing = hasQueriableIndex;
}
}
}
use of org.apache.cassandra.exceptions.InvalidRequestException in project cassandra by apache.
the class StatementRestrictions method processCustomIndexExpressions.
private void processCustomIndexExpressions(List<CustomIndexExpression> expressions, VariableSpecifications boundNames, SecondaryIndexManager indexManager) {
if (expressions.size() > 1)
throw new InvalidRequestException(IndexRestrictions.MULTIPLE_EXPRESSIONS);
CustomIndexExpression expression = expressions.get(0);
CFName cfName = expression.targetIndex.getCfName();
if (cfName.hasKeyspace() && !expression.targetIndex.getKeyspace().equals(table.keyspace))
throw IndexRestrictions.invalidIndex(expression.targetIndex, table);
if (cfName.getColumnFamily() != null && !cfName.getColumnFamily().equals(table.name))
throw IndexRestrictions.invalidIndex(expression.targetIndex, table);
if (!table.indexes.has(expression.targetIndex.getIdx()))
throw IndexRestrictions.indexNotFound(expression.targetIndex, table);
Index index = indexManager.getIndex(table.indexes.get(expression.targetIndex.getIdx()).get());
if (!index.getIndexMetadata().isCustom())
throw IndexRestrictions.nonCustomIndexInExpression(expression.targetIndex);
AbstractType<?> expressionType = index.customExpressionValueType();
if (expressionType == null)
throw IndexRestrictions.customExpressionNotSupported(expression.targetIndex);
expression.prepareValue(table, expressionType, boundNames);
filterRestrictions.add(expression);
}
Aggregations