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