use of org.apache.cassandra.cql3.SingleColumnRelation in project cassandra by apache.
the class SSTableGenerator method delete.
Mutation delete(long lts, long pd, Query query) {
Object[] partitionKey = schema.inflatePartitionKey(pd);
WhereClause.Builder builder = new WhereClause.Builder();
List<ColumnIdentifier> variableNames = new ArrayList<>();
List<ByteBuffer> values = new ArrayList<>();
for (int i = 0; i < partitionKey.length; i++) {
String name = schema.partitionKeys.get(i).name;
ColumnMetadata columnDef = metadata.getColumn(ByteBufferUtil.bytes(name));
variableNames.add(columnDef.name);
values.add(ByteBufferUtil.objectToBytes(partitionKey[i]));
builder.add(new SingleColumnRelation(ColumnIdentifier.getInterned(name, true), toOperator(Relation.RelationKind.EQ), new AbstractMarker.Raw(values.size() - 1)));
}
for (Relation relation : query.relations) {
String name = relation.column();
ColumnMetadata columnDef = metadata.getColumn(ByteBufferUtil.bytes(relation.column()));
variableNames.add(columnDef.name);
values.add(ByteBufferUtil.objectToBytes(relation.value()));
builder.add(new SingleColumnRelation(ColumnIdentifier.getInterned(name, false), toOperator(relation.kind), new AbstractMarker.Raw(values.size() - 1)));
}
StatementRestrictions restrictions = new StatementRestrictions(StatementType.DELETE, metadata, builder.build(), new VariableSpecifications(variableNames), false, false, false, false);
QueryOptions options = QueryOptions.forInternalCalls(ConsistencyLevel.QUORUM, values);
SortedSet<ClusteringBound<?>> startBounds = restrictions.getClusteringColumnsBounds(Bound.START, options);
SortedSet<ClusteringBound<?>> endBounds = restrictions.getClusteringColumnsBounds(Bound.END, options);
Slices slices = DeleteStatement.toSlices(metadata, startBounds, endBounds);
assert slices.size() == 1;
int deletionTime = FBUtilities.nowInSeconds();
long rts = clock.rts(lts);
return new RowUpdateBuilder(metadata, deletionTime, rts, metadata.params.defaultTimeToLive, serializePartitionKey(store, partitionKey)).noRowMarker().addRangeTombstone(new RangeTombstone(slices.get(0), new DeletionTime(rts, deletionTime))).build();
}
Aggregations