Search in sources :

Example 11 with InvalidRequestException

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()));
}
Also used : InvalidRequestException(org.apache.cassandra.exceptions.InvalidRequestException) KeyspaceMetadata(org.apache.cassandra.schema.KeyspaceMetadata)

Example 12 with InvalidRequestException

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;
    }
}
Also used : TableMetadata(org.apache.cassandra.schema.TableMetadata) ConfigurationException(org.apache.cassandra.exceptions.ConfigurationException) InvalidRequestException(org.apache.cassandra.exceptions.InvalidRequestException) KeyspaceMetadata(org.apache.cassandra.schema.KeyspaceMetadata) ViewMetadata(org.apache.cassandra.schema.ViewMetadata)

Example 13 with InvalidRequestException

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;
}
Also used : InvalidRequestException(org.apache.cassandra.exceptions.InvalidRequestException)

Example 14 with InvalidRequestException

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;
        }
    }
}
Also used : InvalidRequestException(org.apache.cassandra.exceptions.InvalidRequestException)

Example 15 with InvalidRequestException

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);
}
Also used : InvalidRequestException(org.apache.cassandra.exceptions.InvalidRequestException) Index(org.apache.cassandra.index.Index)

Aggregations

InvalidRequestException (org.apache.cassandra.exceptions.InvalidRequestException)34 ByteBuffer (java.nio.ByteBuffer)8 TableMetadata (org.apache.cassandra.schema.TableMetadata)8 ColumnMetadata (org.apache.cassandra.schema.ColumnMetadata)5 KeyspaceMetadata (org.apache.cassandra.schema.KeyspaceMetadata)4 ArrayList (java.util.ArrayList)3 QueryOptions (org.apache.cassandra.cql3.QueryOptions)3 AbstractType (org.apache.cassandra.db.marshal.AbstractType)3 PartitionUpdate (org.apache.cassandra.db.partitions.PartitionUpdate)3 ViewMetadata (org.apache.cassandra.schema.ViewMetadata)3 java.util (java.util)2 org.apache.cassandra.config (org.apache.cassandra.config)2 UpdateParameters (org.apache.cassandra.cql3.UpdateParameters)2 org.apache.cassandra.db (org.apache.cassandra.db)2 ConfigurationException (org.apache.cassandra.exceptions.ConfigurationException)2 Index (org.apache.cassandra.index.Index)2 Triggers (org.apache.cassandra.schema.Triggers)2 FBUtilities (org.apache.cassandra.utils.FBUtilities)2 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableMap (com.google.common.collect.ImmutableMap)1