Search in sources :

Example 26 with InvalidRequestException

use of org.apache.cassandra.exceptions.InvalidRequestException in project cassandra by apache.

the class DropAggregateStatement method announceMigration.

public Event.SchemaChange announceMigration(QueryState queryState, boolean isLocalOnly) throws RequestValidationException {
    Collection<Function> olds = Schema.instance.getFunctions(functionName);
    if (!argsPresent && olds != null && olds.size() > 1)
        throw new InvalidRequestException(String.format("'DROP AGGREGATE %s' matches multiple function definitions; " + "specify the argument types by issuing a statement like " + "'DROP AGGREGATE %s (type, type, ...)'. Hint: use cqlsh " + "'DESCRIBE AGGREGATE %s' command to find all overloads", functionName, functionName, functionName));
    Function old = null;
    if (argsPresent) {
        if (Schema.instance.getKeyspaceMetadata(functionName.keyspace) != null) {
            List<AbstractType<?>> argTypes = new ArrayList<>(argRawTypes.size());
            for (CQL3Type.Raw rawType : argRawTypes) argTypes.add(prepareType("arguments", rawType));
            old = Schema.instance.findFunction(functionName, argTypes).orElse(null);
        }
        if (old == null || !(old instanceof AggregateFunction)) {
            if (ifExists)
                return null;
            // just build a nicer error message
            StringBuilder sb = new StringBuilder();
            for (CQL3Type.Raw rawType : argRawTypes) {
                if (sb.length() > 0)
                    sb.append(", ");
                sb.append(rawType);
            }
            throw new InvalidRequestException(String.format("Cannot drop non existing aggregate '%s(%s)'", functionName, sb));
        }
    } else {
        if (olds == null || olds.isEmpty() || !(olds.iterator().next() instanceof AggregateFunction)) {
            if (ifExists)
                return null;
            throw new InvalidRequestException(String.format("Cannot drop non existing aggregate '%s'", functionName));
        }
        old = olds.iterator().next();
    }
    if (old.isNative())
        throw new InvalidRequestException(String.format("Cannot drop aggregate '%s' because it is a " + "native (built-in) function", functionName));
    MigrationManager.announceAggregateDrop((UDAggregate) old, isLocalOnly);
    return new Event.SchemaChange(Event.SchemaChange.Change.DROPPED, Event.SchemaChange.Target.AGGREGATE, old.name().keyspace, old.name().name, AbstractType.asCQLTypeStringList(old.argTypes()));
}
Also used : CQL3Type(org.apache.cassandra.cql3.CQL3Type) ArrayList(java.util.ArrayList) AbstractType(org.apache.cassandra.db.marshal.AbstractType) InvalidRequestException(org.apache.cassandra.exceptions.InvalidRequestException)

Example 27 with InvalidRequestException

use of org.apache.cassandra.exceptions.InvalidRequestException in project cassandra by apache.

the class DropTriggerStatement method announceMigration.

public Event.SchemaChange announceMigration(QueryState queryState, boolean isLocalOnly) throws ConfigurationException, InvalidRequestException {
    TableMetadata current = Schema.instance.getTableMetadata(keyspace(), columnFamily());
    Triggers triggers = current.triggers;
    if (!triggers.get(triggerName).isPresent()) {
        if (ifExists)
            return null;
        else
            throw new InvalidRequestException(String.format("Trigger %s was not found", triggerName));
    }
    logger.info("Dropping trigger with name {}", triggerName);
    TableMetadata updated = current.unbuild().triggers(triggers.without(triggerName)).build();
    MigrationManager.announceTableUpdate(updated, isLocalOnly);
    return new Event.SchemaChange(Event.SchemaChange.Change.UPDATED, Event.SchemaChange.Target.TABLE, keyspace(), columnFamily());
}
Also used : TableMetadata(org.apache.cassandra.schema.TableMetadata) Triggers(org.apache.cassandra.schema.Triggers) InvalidRequestException(org.apache.cassandra.exceptions.InvalidRequestException)

Example 28 with InvalidRequestException

use of org.apache.cassandra.exceptions.InvalidRequestException in project cassandra by apache.

the class StressCQLSSTableWriter method rawAddRow.

/**
     * Adds a new row to the writer given already serialized values.
     * <p>
     * This is a shortcut for {@code rawAddRow(Arrays.asList(values))}.
     *
     * @param values the row values (corresponding to the bind variables of the
     * insertion statement used when creating by this writer) as binary.
     * @return this writer.
     */
public StressCQLSSTableWriter rawAddRow(List<ByteBuffer> values) throws InvalidRequestException, IOException {
    if (values.size() != boundNames.size())
        throw new InvalidRequestException(String.format("Invalid number of arguments, expecting %d values but got %d", boundNames.size(), values.size()));
    QueryOptions options = QueryOptions.forInternalCalls(null, values);
    List<ByteBuffer> keys = insert.buildPartitionKeyNames(options);
    SortedSet<Clustering> clusterings = insert.createClustering(options);
    long now = System.currentTimeMillis() * 1000;
    // Note that we asks indexes to not validate values (the last 'false' arg below) because that triggers a 'Keyspace.open'
    // and that forces a lot of initialization that we don't want.
    UpdateParameters params = new UpdateParameters(insert.metadata(), insert.updatedColumns(), options, insert.getTimestamp(now, options), insert.getTimeToLive(options), Collections.<DecoratedKey, Partition>emptyMap());
    try {
        for (ByteBuffer key : keys) {
            for (Clustering clustering : clusterings) insert.addUpdateForKey(writer.getUpdateFor(key), clustering, params);
        }
        return this;
    } catch (SSTableSimpleUnsortedWriter.SyncException e) {
        // wrapped in a SyncException (see BufferedWriter below). We want to extract that IOE.
        throw (IOException) e.getCause();
    }
}
Also used : InvalidRequestException(org.apache.cassandra.exceptions.InvalidRequestException) UpdateParameters(org.apache.cassandra.cql3.UpdateParameters) QueryOptions(org.apache.cassandra.cql3.QueryOptions) ByteBuffer(java.nio.ByteBuffer)

Example 29 with InvalidRequestException

use of org.apache.cassandra.exceptions.InvalidRequestException in project cassandra by apache.

the class UDFunction method execute.

public final ByteBuffer execute(ProtocolVersion protocolVersion, List<ByteBuffer> parameters) {
    assertUdfsEnabled(language);
    if (!isCallableWrtNullable(parameters))
        return null;
    long tStart = System.nanoTime();
    parameters = makeEmptyParametersNull(parameters);
    try {
        // Using async UDF execution is expensive (adds about 100us overhead per invocation on a Core-i7 MBPr).
        ByteBuffer result = DatabaseDescriptor.enableUserDefinedFunctionsThreads() ? executeAsync(protocolVersion, parameters) : executeUserDefined(protocolVersion, parameters);
        Tracing.trace("Executed UDF {} in {}μs", name(), (System.nanoTime() - tStart) / 1000);
        return result;
    } catch (InvalidRequestException e) {
        throw e;
    } catch (Throwable t) {
        logger.trace("Invocation of user-defined function '{}' failed", this, t);
        if (t instanceof VirtualMachineError)
            throw (VirtualMachineError) t;
        throw FunctionExecutionException.create(this, t);
    }
}
Also used : InvalidRequestException(org.apache.cassandra.exceptions.InvalidRequestException) ByteBuffer(java.nio.ByteBuffer)

Example 30 with InvalidRequestException

use of org.apache.cassandra.exceptions.InvalidRequestException in project cassandra by apache.

the class AbstractFunctionSelector method newFactory.

public static Factory newFactory(final Function fun, final SelectorFactories factories) throws InvalidRequestException {
    if (fun.isAggregate()) {
        if (factories.doesAggregation())
            throw new InvalidRequestException("aggregate functions cannot be used as arguments of aggregate functions");
    }
    return new Factory() {

        protected String getColumnName() {
            return fun.columnName(factories.getColumnNames());
        }

        protected AbstractType<?> getReturnType() {
            return fun.returnType();
        }

        protected void addColumnMapping(SelectionColumnMapping mapping, ColumnSpecification resultsColumn) {
            SelectionColumnMapping tmpMapping = SelectionColumnMapping.newMapping();
            for (Factory factory : factories) factory.addColumnMapping(tmpMapping, resultsColumn);
            if (tmpMapping.getMappings().get(resultsColumn).isEmpty())
                // add a null mapping for cases where there are no
                // further selectors, such as no-arg functions and count
                mapping.addMapping(resultsColumn, (ColumnMetadata) null);
            else
                // collate the mapped columns from the child factories & add those
                mapping.addMapping(resultsColumn, tmpMapping.getMappings().values());
        }

        public void addFunctionsTo(List<Function> functions) {
            fun.addFunctionsTo(functions);
            factories.addFunctionsTo(functions);
        }

        public Selector newInstance(QueryOptions options) throws InvalidRequestException {
            return fun.isAggregate() ? new AggregateFunctionSelector(fun, factories.newInstances(options)) : new ScalarFunctionSelector(fun, factories.newInstances(options));
        }

        public boolean isWritetimeSelectorFactory() {
            return factories.containsWritetimeSelectorFactory();
        }

        public boolean isTTLSelectorFactory() {
            return factories.containsTTLSelectorFactory();
        }

        public boolean isAggregateSelectorFactory() {
            return fun.isAggregate() || factories.doesAggregation();
        }
    };
}
Also used : ColumnSpecification(org.apache.cassandra.cql3.ColumnSpecification) ColumnMetadata(org.apache.cassandra.schema.ColumnMetadata) InvalidRequestException(org.apache.cassandra.exceptions.InvalidRequestException) List(java.util.List) QueryOptions(org.apache.cassandra.cql3.QueryOptions)

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