public void addConditions(Composite clusteringPrefix, CQL3CasRequest request, QueryOptions options) throws InvalidRequestException { if (ifNotExists) { // If we use ifNotExists, if the statement applies to any non static columns, then the condition is on the row of the non-static // columns and the prefix should be the clusteringPrefix. But if only static columns are set, then the ifNotExists apply to the existence // of any static columns and we should use the prefix for the "static part" of the partition. request.addNotExist(clusteringPrefix); } else if (ifExists) { request.addExist(clusteringPrefix); } else { if (columnConditions != null) request.addConditions(clusteringPrefix, columnConditions, options); if (staticConditions != null) request.addConditions(cfm.comparator.staticPrefix(), staticConditions, options); } }
public void addNotExist(Clustering clustering) throws InvalidRequestException { addExistsCondition(clustering, new NotExistCondition(clustering), true); }
static RowIterator casInternal(CQL3CasRequest request, QueryState state) { UUID ballot = UUIDGen.getTimeUUIDFromMicros(state.getTimestamp()); SinglePartitionReadCommand readCommand = request.readCommand(FBUtilities.nowInSeconds()); FilteredPartition current; try (ReadExecutionController executionController = readCommand.executionController(); PartitionIterator iter = readCommand.executeInternal(executionController)) { current = FilteredPartition.create(PartitionIterators.getOnlyElement(iter, readCommand)); } if (!request.appliesTo(current)) return current.rowIterator(); PartitionUpdate updates = request.makeUpdates(current); updates = TriggerExecutor.instance.execute(updates); Commit proposal = Commit.newProposal(ballot, updates); proposal.makeMutation().apply(); return null; }
casRequest = new CQL3CasRequest(statement.cfm, key, true, conditionColumns, updatesRegularRows, updatesStaticRow); casRequest.addRangeDeletion(slice, statement, statementOptions, timestamp); Iterables.addAll(columnsWithConditions, statement.getColumnsWithConditions()); casRequest.addRowUpdate(clustering, statement, statementOptions, timestamp);
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; }
static ColumnFamily casInternal(CQL3CasRequest request, QueryState state) throws InvalidRequestException { UUID ballot = UUIDGen.getTimeUUIDFromMicros(state.getTimestamp()); CFMetaData metadata = Schema.instance.getCFMetaData(request.cfm.ksName, request.cfm.cfName); ReadCommand readCommand = ReadCommand.create(request.cfm.ksName, request.key, request.cfm.cfName, request.now, request.readFilter()); Keyspace keyspace = Keyspace.open(request.cfm.ksName); Row row = readCommand.getRow(keyspace); ColumnFamily current = row.cf; if (current == null) current = ArrayBackedSortedColumns.factory.create(metadata); if (!request.appliesTo(current)) { return current; } ColumnFamily updates = request.makeUpdates(current); updates = TriggerExecutor.instance.execute(request.key, updates); Commit proposal = Commit.newProposal(request.key, ballot, updates); proposal.makeMutation().apply(); return null; }
@Override public void addConditionsTo(CQL3CasRequest request, Clustering clustering, QueryOptions options) { request.addExist(clustering); }
@Override public void addConditionsTo(CQL3CasRequest request, Clustering clustering, QueryOptions options) { request.addNotExist(clustering); }
/** * Adds the conditions to the specified CAS request. * * @param request the request * @param clustering the clustering prefix * @param options the query options */ public void addConditionsTo(CQL3CasRequest request, Clustering clustering, QueryOptions options) { if (!columnConditions.isEmpty()) request.addConditions(clustering, columnConditions, options); if (!staticConditions.isEmpty()) request.addConditions(Clustering.STATIC_CLUSTERING, staticConditions, options); }
public SinglePartitionReadCommand readCommand(int nowInSec) { assert staticConditions != null || !conditions.isEmpty(); // Fetch all columns, but query only the selected ones ColumnFilter columnFilter = ColumnFilter.selection(columnsToRead()); // With only a static condition, we still want to make the distinction between a non-existing partition and one // that exists (has some live data) but has not static content. So we query the first live row of the partition. if (conditions.isEmpty()) return SinglePartitionReadCommand.create(cfm, nowInSec, columnFilter, RowFilter.NONE, DataLimits.cqlLimits(1), key, new ClusteringIndexSliceFilter(Slices.ALL, false)); ClusteringIndexNamesFilter filter = new ClusteringIndexNamesFilter(conditions.navigableKeySet(), false); return SinglePartitionReadCommand.create(cfm, nowInSec, key, columnFilter, filter); }
static RowIterator casInternal(CQL3CasRequest request, QueryState state) { UUID ballot = UUIDGen.getTimeUUIDFromMicros(state.getTimestamp()); SinglePartitionReadCommand readCommand = request.readCommand(FBUtilities.nowInSeconds()); FilteredPartition current; try (ReadExecutionController executionController = readCommand.executionController(); PartitionIterator iter = readCommand.executeInternal(executionController)) { current = FilteredPartition.create(PartitionIterators.getOnlyElement(iter, readCommand)); } if (!request.appliesTo(current)) return current.rowIterator(); PartitionUpdate updates = request.makeUpdates(current); updates = TriggerExecutor.instance.execute(updates); Commit proposal = Commit.newProposal(ballot, updates); proposal.makeMutation().apply(); return null; }
casRequest = new CQL3CasRequest(statement.cfm, key, true, conditionColumns, updatesRegularRows, updatesStaticRow); casRequest.addRangeDeletion(slice, statement, statementOptions, timestamp); Iterables.addAll(columnsWithConditions, statement.getColumnsWithConditions()); casRequest.addRowUpdate(clustering, statement, statementOptions, timestamp);
casRequest = new CQL3CasRequest(statement.cfm, key, true); Iterables.addAll(columnsWithConditions, statement.getColumnsWithConditions()); casRequest.addRowUpdate(clusteringPrefix, statement, statementOptions, timestamp);
@Override public void addConditionsTo(CQL3CasRequest request, Clustering clustering, QueryOptions options) { request.addExist(clustering); }
@Override public void addConditionsTo(CQL3CasRequest request, Clustering clustering, QueryOptions options) { request.addNotExist(clustering); }
/** * Adds the conditions to the specified CAS request. * * @param request the request * @param clustering the clustering prefix * @param options the query options */ public void addConditionsTo(CQL3CasRequest request, Clustering clustering, QueryOptions options) { if (!columnConditions.isEmpty()) request.addConditions(clustering, columnConditions, options); if (!staticConditions.isEmpty()) request.addConditions(Clustering.STATIC_CLUSTERING, staticConditions, options); }
public SinglePartitionReadCommand readCommand(int nowInSec) { assert staticConditions != null || !conditions.isEmpty(); // Fetch all columns, but query only the selected ones ColumnFilter columnFilter = ColumnFilter.selection(columnsToRead()); // With only a static condition, we still want to make the distinction between a non-existing partition and one // that exists (has some live data) but has not static content. So we query the first live row of the partition. if (conditions.isEmpty()) return SinglePartitionReadCommand.create(cfm, nowInSec, columnFilter, RowFilter.NONE, DataLimits.cqlLimits(1), key, new ClusteringIndexSliceFilter(Slices.ALL, false)); ClusteringIndexNamesFilter filter = new ClusteringIndexNamesFilter(conditions.navigableKeySet(), false); return SinglePartitionReadCommand.create(cfm, nowInSec, key, columnFilter, filter); }
static RowIterator casInternal(CQL3CasRequest request, QueryState state) { UUID ballot = UUIDGen.getTimeUUIDFromMicros(state.getTimestamp()); SinglePartitionReadCommand readCommand = request.readCommand(FBUtilities.nowInSeconds()); FilteredPartition current; try (ReadExecutionController executionController = readCommand.executionController(); PartitionIterator iter = readCommand.executeInternal(executionController)) { current = FilteredPartition.create(PartitionIterators.getOnlyElement(iter, readCommand)); } if (!request.appliesTo(current)) return current.rowIterator(); PartitionUpdate updates = request.makeUpdates(current); updates = TriggerExecutor.instance.execute(updates); Commit proposal = Commit.newProposal(ballot, updates); proposal.makeMutation().apply(); return null; }
casRequest = new CQL3CasRequest(statement.cfm, key, true, conditionColumns, updatesRegularRows, updatesStaticRow); casRequest.addRangeDeletion(slice, statement, statementOptions, timestamp); Iterables.addAll(columnsWithConditions, statement.getColumnsWithConditions()); casRequest.addRowUpdate(clustering, statement, statementOptions, timestamp);
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; }