Search in sources :

Example 1 with SingleColumnRelation

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();
}
Also used : ColumnMetadata(org.apache.cassandra.schema.ColumnMetadata) Slices(org.apache.cassandra.db.Slices) RowUpdateBuilder(org.apache.cassandra.db.RowUpdateBuilder) WhereClause(org.apache.cassandra.cql3.WhereClause) ArrayList(java.util.ArrayList) QueryOptions(org.apache.cassandra.cql3.QueryOptions) SingleColumnRelation(org.apache.cassandra.cql3.SingleColumnRelation) Relation(harry.operations.Relation) RowUpdateBuilder(org.apache.cassandra.db.RowUpdateBuilder) StatementRestrictions(org.apache.cassandra.cql3.restrictions.StatementRestrictions) RangeTombstone(org.apache.cassandra.db.RangeTombstone) DeletionTime(org.apache.cassandra.db.DeletionTime) ByteBuffer(java.nio.ByteBuffer) VariableSpecifications(org.apache.cassandra.cql3.VariableSpecifications) SingleColumnRelation(org.apache.cassandra.cql3.SingleColumnRelation) ClusteringBound(org.apache.cassandra.db.ClusteringBound) ColumnIdentifier(org.apache.cassandra.cql3.ColumnIdentifier)

Aggregations

Relation (harry.operations.Relation)1 ByteBuffer (java.nio.ByteBuffer)1 ArrayList (java.util.ArrayList)1 ColumnIdentifier (org.apache.cassandra.cql3.ColumnIdentifier)1 QueryOptions (org.apache.cassandra.cql3.QueryOptions)1 SingleColumnRelation (org.apache.cassandra.cql3.SingleColumnRelation)1 VariableSpecifications (org.apache.cassandra.cql3.VariableSpecifications)1 WhereClause (org.apache.cassandra.cql3.WhereClause)1 StatementRestrictions (org.apache.cassandra.cql3.restrictions.StatementRestrictions)1 ClusteringBound (org.apache.cassandra.db.ClusteringBound)1 DeletionTime (org.apache.cassandra.db.DeletionTime)1 RangeTombstone (org.apache.cassandra.db.RangeTombstone)1 RowUpdateBuilder (org.apache.cassandra.db.RowUpdateBuilder)1 Slices (org.apache.cassandra.db.Slices)1 ColumnMetadata (org.apache.cassandra.schema.ColumnMetadata)1