private ResultSet buildCasResultSet(RowIterator partition, QueryOptions options) throws InvalidRequestException { return buildCasResultSet(keyspace(), columnFamily(), partition, getColumnsWithConditions(), false, options); }
public void applyUpdates(FilteredPartition current, PartitionUpdate updates) throws InvalidRequestException { Map<DecoratedKey, Partition> map = stmt.requiresRead() ? Collections.<DecoratedKey, Partition>singletonMap(key, current) : null; UpdateParameters params = new UpdateParameters(cfm, updates.columns(), options, timestamp, stmt.getTimeToLive(options), map); stmt.addUpdateForKey(updates, clustering, params); } }
/** * Checks that the modification only apply to static columns. * @return <code>true</code> if the modification only apply to static columns, <code>false</code> otherwise. */ private boolean appliesOnlyToStaticColumns() { return appliesOnlyToStaticColumns(operations, conditions); }
public ResultMessage executeInternalWithCondition(QueryState state, QueryOptions options) throws RequestValidationException, RequestExecutionException { CQL3CasRequest request = makeCasRequest(state, options); ColumnFamily result = casInternal(request, state); return new ResultMessage.Rows(buildCasResultSet(request.key, result, options)); }
public void checkAccess(ClientState state) throws InvalidRequestException, UnauthorizedException { state.hasColumnFamilyAccess(keyspace(), columnFamily(), Permission.MODIFY); // CAS updates can be used to simulate a SELECT query, so should require Permission.SELECT as well. if (hasConditions()) state.hasColumnFamilyAccess(keyspace(), columnFamily(), Permission.SELECT); }
QueryOptions statementOptions = options.forStatement(i); long timestamp = attrs.getTimestamp(now, statementOptions); List<ByteBuffer> pks = statement.buildPartitionKeyNames(statementOptions); if (statement.getRestrictions().keyIsInRelation()) throw new IllegalArgumentException("Batch with conditions cannot span multiple partitions (you cannot use IN on the partition key)"); if (key == null) checkFalse(statement.getRestrictions().clusteringKeyRestrictionsHasIN(), "IN on the clustering key columns is not supported with conditional %s", statement.type.isUpdate()? "updates" : "deletions"); if (statement.hasSlices()) assert !statement.hasConditions(); Slices slices = statement.createSlices(statementOptions); Clustering clustering = Iterables.getOnlyElement(statement.createClustering(statementOptions)); if (statement.hasConditions()) statement.addConditions(clustering, casRequest, statementOptions); if (statement.hasIfNotExistCondition() || statement.hasIfExistCondition()) columnsWithConditions = null; else if (columnsWithConditions != null) Iterables.addAll(columnsWithConditions, statement.getColumnsWithConditions());
public ResultMessage executeWithCondition(QueryState queryState, QueryOptions options) throws RequestExecutionException, RequestValidationException { CQL3CasRequest request = makeCasRequest(queryState, options); ColumnFamily result = StorageProxy.cas(keyspace(), columnFamily(), request.key, request, options.getSerialConsistency(), options.getConsistency(), queryState.getClientState()); return new ResultMessage.Rows(buildCasResultSet(request.key, result, options)); }
if (timestampSet && statement.isCounter()) throw new InvalidRequestException("Cannot provide custom timestamp for a BATCH containing counters"); if (timestampSet && statement.isTimestampSet()) throw new InvalidRequestException("Timestamp must be set either on BATCH or individual statements"); if (type == Type.COUNTER && !statement.isCounter()) throw new InvalidRequestException("Cannot include non-counter statement in a counter batch"); if (type == Type.LOGGED && statement.isCounter()) throw new InvalidRequestException("Cannot include a counter statement in a logged batch"); if (statement.isCounter()) hasCounters = true; else for (ModificationStatement stmt : statements) if (ksName != null && (!stmt.keyspace().equals(ksName) || !stmt.columnFamily().equals(cfName))) throw new InvalidRequestException("Batch with conditions cannot span multiple tables"); ksName = stmt.keyspace(); cfName = stmt.columnFamily();
long queryStartNanoTime) List<ByteBuffer> keys = buildPartitionKeyNames(options); if (hasSlices()) Slices slices = createSlices(options); return; UpdateParameters params = makeUpdateParameters(keys, new ClusteringIndexSliceFilter(slices, false), options, addUpdateForKey(upd, slice, params); NavigableSet<Clustering> clusterings = createClustering(options); return; UpdateParameters params = makeUpdateParameters(keys, clusterings, options, local, now, queryStartNanoTime); addUpdateForKey(upd, Clustering.EMPTY, params); addUpdateForKey(upd, clustering, params);
private CQL3CasRequest makeCasRequest(QueryState queryState, QueryOptions options) { List<ByteBuffer> keys = buildPartitionKeyNames(options); // We don't support IN for CAS operation so far checkFalse(restrictions.keyIsInRelation(), "IN on the partition key is not supported with conditional %s", type.isUpdate()? "updates" : "deletions"); DecoratedKey key = cfm.decorateKey(keys.get(0)); long now = options.getTimestamp(queryState); checkFalse(restrictions.clusteringKeyRestrictionsHasIN(), "IN on the clustering key columns is not supported with conditional %s", type.isUpdate()? "updates" : "deletions"); Clustering clustering = Iterables.getOnlyElement(createClustering(options)); CQL3CasRequest request = new CQL3CasRequest(cfm, key, false, conditionColumns(), updatesRegularRows(), updatesStaticRow()); addConditions(clustering, request, options); request.addRowUpdate(clustering, this, options, now); return request; }
private Query createQuery(final long startTime, final long execTime, final String queryString, final ModificationStatement statement, final QueryState queryState, final QueryOptions options) { return Query.create(startTime, execTime, queryState.getClientState().getRemoteAddress().toString(), Query.StatementType.UPDATE, statement.keyspace(), statement.columnFamily(), queryString, extractConsistencyLevel(options)); }
public void checkAccess(ClientState state) throws InvalidRequestException, UnauthorizedException { state.hasColumnFamilyAccess(cfm, Permission.MODIFY); // CAS updates can be used to simulate a SELECT query, so should require Permission.SELECT as well. if (hasConditions()) state.hasColumnFamilyAccess(cfm, Permission.SELECT); // MV updates need to get the current state from the table, and might update the views // Require Permission.SELECT on the base table, and Permission.MODIFY on the views Iterator<ViewDefinition> views = View.findAll(keyspace(), columnFamily()).iterator(); if (views.hasNext()) { state.hasColumnFamilyAccess(cfm, Permission.SELECT); do { state.hasColumnFamilyAccess(views.next().metadata, Permission.MODIFY); } while (views.hasNext()); } for (Function function : getFunctions()) state.ensureHasPermission(Permission.EXECUTE, function); }
QueryOptions statementOptions = options.forStatement(i); long timestamp = attrs.getTimestamp(now, statementOptions); List<ByteBuffer> pks = statement.buildPartitionKeyNames(statementOptions); if (pks.size() > 1) throw new IllegalArgumentException("Batch with conditions cannot span multiple partitions (you cannot use IN on the partition key)"); Composite clusteringPrefix = statement.createClusteringPrefix(statementOptions); if (statement.hasConditions()) statement.addConditions(clusteringPrefix, casRequest, statementOptions); if (statement.hasIfNotExistCondition() || statement.hasIfExistCondition()) columnsWithConditions = null; else if (columnsWithConditions != null) Iterables.addAll(columnsWithConditions, statement.getColumnsWithConditions());
long queryStartNanoTime) if (!requiresRead()) return null; cl.validateForRead(keyspace()); PartitionIterator iter = group.executeInternal(executionController)) return asMaterializedMap(iter); return asMaterializedMap(iter);
throws RequestExecutionException, RequestValidationException String ksName = statement.keyspace(); Map<ByteBuffer, IMutation> ksMap = mutations.get(ksName); if (ksMap == null) List<ByteBuffer> keys = statement.buildPartitionKeyNames(options); Composite clusteringPrefix = statement.createClusteringPrefix(options); UpdateParameters params = statement.makeUpdateParameters(keys, clusteringPrefix, options, local, now); statement.addUpdateForKey(mut.addOrGet(statement.cfm), key, clusteringPrefix, params);
/** * Convert statement into a list of mutations to apply on the server * * @param options value for prepared statement markers * @param local if true, any requests (for collections) performed by getMutation should be done locally only. * @param now the current timestamp in microseconds to use if no timestamp is user provided. * * @return list of the mutations * @throws InvalidRequestException on invalid requests */ private Collection<? extends IMutation> getMutations(QueryOptions options, boolean local, long now) throws RequestExecutionException, RequestValidationException { List<ByteBuffer> keys = buildPartitionKeyNames(options); Composite clusteringPrefix = createClusteringPrefix(options); UpdateParameters params = makeUpdateParameters(keys, clusteringPrefix, options, local, now); Collection<IMutation> mutations = new ArrayList<IMutation>(keys.size()); for (ByteBuffer key: keys) { ThriftValidation.validateKey(cfm, key); ColumnFamily cf = ArrayBackedSortedColumns.factory.create(cfm); addUpdateForKey(cf, key, clusteringPrefix, params); Mutation mut = new Mutation(cfm.ksName, key, cf); mutations.add(isCounter() ? new CounterMutation(mut, options.getConsistency()) : mut); } return mutations; }
protected Map<ByteBuffer, CQL3Row> readRequiredRows(Collection<ByteBuffer> partitionKeys, Composite clusteringPrefix, boolean local, ConsistencyLevel cl) throws RequestExecutionException, RequestValidationException if (!requiresRead()) return null; cl.validateForRead(keyspace()); long now = System.currentTimeMillis(); for (ByteBuffer key : partitionKeys) commands.add(new SliceFromReadCommand(keyspace(), key, columnFamily(), now, new SliceQueryFilter(slices, false, Integer.MAX_VALUE))); ? SelectStatement.readLocally(keyspace(), commands) : StorageProxy.read(commands, cl);
public static ResultSet buildCasResultSet(String ksName, ByteBuffer key, String cfName, ColumnFamily cf, Iterable<ColumnDefinition> columnsWithConditions, boolean isBatch, QueryOptions options) throws InvalidRequestException { boolean success = cf == null; ColumnSpecification spec = new ColumnSpecification(ksName, cfName, CAS_RESULT_COLUMN, BooleanType.instance); ResultSet.Metadata metadata = new ResultSet.Metadata(Collections.singletonList(spec)); List<List<ByteBuffer>> rows = Collections.singletonList(Collections.singletonList(BooleanType.instance.decompose(success))); ResultSet rs = new ResultSet(metadata, rows); return success ? rs : merge(rs, buildCasFailureResultSet(key, cf, columnsWithConditions, isBatch, options)); }
private ResultMessage executeInternalWithConditions(BatchQueryOptions options, QueryState state) throws RequestExecutionException, RequestValidationException { Pair<CQL3CasRequest, Set<ColumnDefinition>> p = makeCasRequest(options, state); CQL3CasRequest request = p.left; Set<ColumnDefinition> columnsWithConditions = p.right; String ksName = request.cfm.ksName; String tableName = request.cfm.cfName; try (RowIterator result = ModificationStatement.casInternal(request, state)) { return new ResultMessage.Rows(ModificationStatement.buildCasResultSet(ksName, tableName, result, columnsWithConditions, true, options.forStatement(0))); } }
private CQL3CasRequest makeCasRequest(QueryState queryState, QueryOptions options) throws InvalidRequestException { List<ByteBuffer> keys = buildPartitionKeyNames(options); // We don't support IN for CAS operation so far if (keys.size() > 1) throw new InvalidRequestException("IN on the partition key is not supported with conditional updates"); ByteBuffer key = keys.get(0); long now = options.getTimestamp(queryState); Composite prefix = createClusteringPrefix(options); CQL3CasRequest request = new CQL3CasRequest(cfm, key, false); addConditions(prefix, request, options); request.addRowUpdate(prefix, this, options, now); return request; }