Search in sources :

Example 16 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)

Example 17 with InvalidRequestException

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

the class TupleType method split.

/**
     * Split a tuple value into its component values.
     */
public ByteBuffer[] split(ByteBuffer value) {
    ByteBuffer[] components = new ByteBuffer[size()];
    ByteBuffer input = value.duplicate();
    for (int i = 0; i < size(); i++) {
        if (!input.hasRemaining())
            return Arrays.copyOfRange(components, 0, i);
        int size = input.getInt();
        if (input.remaining() < size)
            throw new MarshalException(String.format("Not enough bytes to read %dth component", i));
        // size < 0 means null value
        components[i] = size < 0 ? null : ByteBufferUtil.readBytes(input, size);
    }
    // error out if we got more values in the tuple/UDT than we expected
    if (input.hasRemaining()) {
        throw new InvalidRequestException(String.format("Expected %s %s for %s column, but got more", size(), size() == 1 ? "value" : "values", this.asCQL3Type()));
    }
    return components;
}
Also used : InvalidRequestException(org.apache.cassandra.exceptions.InvalidRequestException) ByteBuffer(java.nio.ByteBuffer)

Example 18 with InvalidRequestException

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

the class SASIIndex method searcherFor.

public Searcher searcherFor(ReadCommand command) throws InvalidRequestException {
    TableMetadata config = command.metadata();
    ColumnFamilyStore cfs = Schema.instance.getColumnFamilyStoreInstance(config.id);
    return controller -> new QueryPlan(cfs, command, DatabaseDescriptor.getRangeRpcTimeout()).execute(controller);
}
Also used : TableMetadata(org.apache.cassandra.schema.TableMetadata) org.apache.cassandra.config(org.apache.cassandra.config) java.util(java.util) CompactionManager(org.apache.cassandra.db.compaction.CompactionManager) PartitionUpdate(org.apache.cassandra.db.partitions.PartitionUpdate) ColumnMetadata(org.apache.cassandra.schema.ColumnMetadata) BiFunction(java.util.function.BiFunction) org.apache.cassandra.db(org.apache.cassandra.db) PerSSTableIndexWriter(org.apache.cassandra.index.sasi.disk.PerSSTableIndexWriter) Callable(java.util.concurrent.Callable) AbstractType(org.apache.cassandra.db.marshal.AbstractType) QueryPlan(org.apache.cassandra.index.sasi.plan.QueryPlan) SSTableReader(org.apache.cassandra.io.sstable.format.SSTableReader) Tracker(org.apache.cassandra.db.lifecycle.Tracker) Schema(org.apache.cassandra.schema.Schema) OpOrder(org.apache.cassandra.utils.concurrent.OpOrder) Row(org.apache.cassandra.db.rows.Row) Operator(org.apache.cassandra.cql3.Operator) ConfigurationException(org.apache.cassandra.exceptions.ConfigurationException) OperationType(org.apache.cassandra.db.compaction.OperationType) Pair(org.apache.cassandra.utils.Pair) Murmur3Partitioner(org.apache.cassandra.dht.Murmur3Partitioner) Descriptor(org.apache.cassandra.io.sstable.Descriptor) IndexTarget(org.apache.cassandra.cql3.statements.IndexTarget) IndexMode(org.apache.cassandra.index.sasi.conf.IndexMode) Index(org.apache.cassandra.index.Index) InvalidRequestException(org.apache.cassandra.exceptions.InvalidRequestException) ColumnIndex(org.apache.cassandra.index.sasi.conf.ColumnIndex) TargetParser(org.apache.cassandra.index.TargetParser) RowFilter(org.apache.cassandra.db.filter.RowFilter) Mode(org.apache.cassandra.index.sasi.disk.OnDiskIndexBuilder.Mode) IndexTransaction(org.apache.cassandra.index.transactions.IndexTransaction) FBUtilities(org.apache.cassandra.utils.FBUtilities) org.apache.cassandra.notifications(org.apache.cassandra.notifications) IndexMetadata(org.apache.cassandra.schema.IndexMetadata) IndexRegistry(org.apache.cassandra.index.IndexRegistry) Iterables(com.googlecode.concurrenttrees.common.Iterables) SecondaryIndexBuilder(org.apache.cassandra.index.SecondaryIndexBuilder) SSTableFlushObserver(org.apache.cassandra.io.sstable.format.SSTableFlushObserver) TableMetadata(org.apache.cassandra.schema.TableMetadata) PartitionIterator(org.apache.cassandra.db.partitions.PartitionIterator) QueryPlan(org.apache.cassandra.index.sasi.plan.QueryPlan)

Example 19 with InvalidRequestException

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

the class BatchMessage method execute.

public Message.Response execute(QueryState state, long queryStartNanoTime) {
    try {
        UUID tracingId = null;
        if (isTracingRequested()) {
            tracingId = UUIDGen.getTimeUUID();
            state.prepareTracingSession(tracingId);
        }
        if (state.traceNextQuery()) {
            state.createTracingSession();
            ImmutableMap.Builder<String, String> builder = ImmutableMap.builder();
            if (options.getConsistency() != null)
                builder.put("consistency_level", options.getConsistency().name());
            if (options.getSerialConsistency() != null)
                builder.put("serial_consistency_level", options.getSerialConsistency().name());
            // TODO we don't have [typed] access to CQL bind variables here.  CASSANDRA-4560 is open to add support.
            Tracing.instance.begin("Execute batch of CQL3 queries", state.getClientAddress(), builder.build());
        }
        QueryHandler handler = ClientState.getCQLQueryHandler();
        List<ParsedStatement.Prepared> prepared = new ArrayList<>(queryOrIdList.size());
        for (int i = 0; i < queryOrIdList.size(); i++) {
            Object query = queryOrIdList.get(i);
            ParsedStatement.Prepared p;
            if (query instanceof String) {
                p = QueryProcessor.parseStatement((String) query, state);
            } else {
                p = handler.getPrepared((MD5Digest) query);
                if (p == null)
                    throw new PreparedQueryNotFoundException((MD5Digest) query);
            }
            List<ByteBuffer> queryValues = values.get(i);
            if (queryValues.size() != p.statement.getBoundTerms())
                throw new InvalidRequestException(String.format("There were %d markers(?) in CQL but %d bound variables", p.statement.getBoundTerms(), queryValues.size()));
            prepared.add(p);
        }
        BatchQueryOptions batchOptions = BatchQueryOptions.withPerStatementVariables(options, values, queryOrIdList);
        List<ModificationStatement> statements = new ArrayList<>(prepared.size());
        for (int i = 0; i < prepared.size(); i++) {
            ParsedStatement.Prepared p = prepared.get(i);
            batchOptions.prepareStatement(i, p.boundNames);
            if (!(p.statement instanceof ModificationStatement))
                throw new InvalidRequestException("Invalid statement in batch: only UPDATE, INSERT and DELETE statements are allowed.");
            statements.add((ModificationStatement) p.statement);
        }
        // Note: It's ok at this point to pass a bogus value for the number of bound terms in the BatchState ctor
        // (and no value would be really correct, so we prefer passing a clearly wrong one).
        BatchStatement batch = new BatchStatement(-1, batchType, statements, Attributes.none());
        Message.Response response = handler.processBatch(batch, state, batchOptions, getCustomPayload(), queryStartNanoTime);
        if (tracingId != null)
            response.setTracingId(tracingId);
        return response;
    } catch (Exception e) {
        JVMStabilityInspector.inspectThrowable(e);
        return ErrorMessage.fromException(e);
    } finally {
        Tracing.instance.stopSession();
    }
}
Also used : ModificationStatement(org.apache.cassandra.cql3.statements.ModificationStatement) ArrayList(java.util.ArrayList) ParsedStatement(org.apache.cassandra.cql3.statements.ParsedStatement) PreparedQueryNotFoundException(org.apache.cassandra.exceptions.PreparedQueryNotFoundException) ByteBuffer(java.nio.ByteBuffer) ImmutableMap(com.google.common.collect.ImmutableMap) PreparedQueryNotFoundException(org.apache.cassandra.exceptions.PreparedQueryNotFoundException) InvalidRequestException(org.apache.cassandra.exceptions.InvalidRequestException) MD5Digest(org.apache.cassandra.utils.MD5Digest) BatchStatement(org.apache.cassandra.cql3.statements.BatchStatement) InvalidRequestException(org.apache.cassandra.exceptions.InvalidRequestException) UUID(java.util.UUID)

Example 20 with InvalidRequestException

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

the class TriggerExecutor method validateForSinglePartition.

private List<PartitionUpdate> validateForSinglePartition(TableId tableId, DecoratedKey key, Collection<Mutation> tmutations) throws InvalidRequestException {
    validate(tmutations);
    if (tmutations.size() == 1) {
        List<PartitionUpdate> updates = Lists.newArrayList(Iterables.getOnlyElement(tmutations).getPartitionUpdates());
        if (updates.size() > 1)
            throw new InvalidRequestException("The updates generated by triggers are not all for the same partition");
        validateSamePartition(tableId, key, Iterables.getOnlyElement(updates));
        return updates;
    }
    ArrayList<PartitionUpdate> updates = new ArrayList<>(tmutations.size());
    for (Mutation mutation : tmutations) {
        for (PartitionUpdate update : mutation.getPartitionUpdates()) {
            validateSamePartition(tableId, key, update);
            updates.add(update);
        }
    }
    return updates;
}
Also used : InvalidRequestException(org.apache.cassandra.exceptions.InvalidRequestException) PartitionUpdate(org.apache.cassandra.db.partitions.PartitionUpdate)

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