diff --git a/configure.py b/configure.py index f4d81dcce0..076992ed99 100755 --- a/configure.py +++ b/configure.py @@ -230,6 +230,7 @@ deps = { 'cql3/functions/functions.cc', 'cql3/statements/modification_statement.cc', 'cql3/statements/update_statement.cc', + 'cql3/statements/delete_statement.cc', 'thrift/handler.cc', 'thrift/server.cc', 'thrift/thrift_validation.cc', diff --git a/cql3/statements/delete_statement.cc b/cql3/statements/delete_statement.cc new file mode 100644 index 0000000000..49cfa404c7 --- /dev/null +++ b/cql3/statements/delete_statement.cc @@ -0,0 +1,56 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* + * Copyright 2015 Cloudius Systems + * + * Modified by Cloudius Systems + */ + +#include "delete_statement.hh" + +namespace cql3 { + +namespace statements { + +void delete_statement::add_update_for_key(api::mutation& m, const api::clustering_prefix& prefix, const update_parameters& params) { + if (_column_operations.empty()) { + m.p.apply_delete(prefix, params.make_tombstone()); + return; + } + + if (prefix.size() < s->clustering_key.size()) { + // In general, we can't delete specific columns if not all clustering columns have been specified. + // However, if we delete only static columns, it's fine since we won't really use the prefix anyway. + for (auto&& deletion : _column_operations) { + if (!deletion->column.is_static()) { + throw exceptions::invalid_request_exception(sprint( + "Primary key column '%s' must be specified in order to delete column '%s'", + get_first_empty_key()->name, deletion->column.name)); + } + } + } + + for (auto&& op : _column_operations) { + op->execute(m, prefix, params); + } +} + +} + +} diff --git a/cql3/statements/DeleteStatement.java b/cql3/statements/delete_statement.hh similarity index 65% rename from cql3/statements/DeleteStatement.java rename to cql3/statements/delete_statement.hh index ff685cfde4..d2f9a289cf 100644 --- a/cql3/statements/DeleteStatement.java +++ b/cql3/statements/delete_statement.hh @@ -15,8 +15,25 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.cassandra.cql3.statements; +/* + * Copyright 2015 Cloudius Systems + * + * Modified by Cloudius Systems + */ + +#pragma once + +#include "cql3/statements/modification_statement.hh" +#include "cql3/attributes.hh" +#include "cql3/operation.hh" +#include "db/api.hh" + +namespace cql3 { + +namespace statements { + +#if 0 import java.nio.ByteBuffer; import java.util.*; @@ -30,63 +47,24 @@ import org.apache.cassandra.db.*; import org.apache.cassandra.db.composites.Composite; import org.apache.cassandra.exceptions.*; import org.apache.cassandra.utils.Pair; +#endif /** - * A DELETE parsed from a CQL query statement. - */ -public class DeleteStatement extends ModificationStatement -{ - private DeleteStatement(StatementType type, int boundTerms, CFMetaData cfm, Attributes attrs) - { - super(type, boundTerms, cfm, attrs); - } +* A DELETE parsed from a CQL query statement. +*/ +class delete_statement : public modification_statement { +public: + delete_statement(statement_type type, int32_t bound_terms, schema_ptr s, std::unique_ptr attrs) + : modification_statement{type, bound_terms, std::move(s), std::move(attrs)} + { } - public boolean requireFullClusteringKey() - { + virtual bool require_full_clustering_key() const override { return false; } - public void addUpdateForKey(ColumnFamily cf, ByteBuffer key, Composite prefix, UpdateParameters params) - throws InvalidRequestException - { - List deletions = getOperations(); - - if (prefix.size() < cfm.clusteringColumns().size() && !deletions.isEmpty()) - { - // In general, we can't delete specific columns if not all clustering columns have been specified. - // However, if we delete only static colums, it's fine since we won't really use the prefix anyway. - for (Operation deletion : deletions) - if (!deletion.column.isStatic()) - throw new InvalidRequestException(String.format("Primary key column '%s' must be specified in order to delete column '%s'", getFirstEmptyKey().name, deletion.column.name)); - } - - if (deletions.isEmpty()) - { - // We delete the slice selected by the prefix. - // However, for performance reasons, we distinguish 2 cases: - // - It's a full internal row delete - // - It's a full cell name (i.e it's a dense layout and the prefix is full) - if (prefix.isEmpty()) - { - // No columns specified, delete the row - cf.delete(new DeletionInfo(params.timestamp, params.localDeletionTime)); - } - else if (cfm.comparator.isDense() && prefix.size() == cfm.clusteringColumns().size()) - { - cf.addAtom(params.makeTombstone(cfm.comparator.create(prefix, null))); - } - else - { - cf.addAtom(params.makeRangeTombstone(prefix.slice())); - } - } - else - { - for (Operation op : deletions) - op.execute(key, cf, prefix, params); - } - } + virtual void add_update_for_key(api::mutation& m, const api::clustering_prefix& prefix, const update_parameters& params) override; +#if 0 protected void validateWhereClauseForConditions() throws InvalidRequestException { Iterator iterator = Iterators.concat(cfm.partitionKeyColumns().iterator(), cfm.clusteringColumns().iterator()); @@ -146,4 +124,9 @@ public class DeleteStatement extends ModificationStatement return stmt; } } +#endif +}; + +} + }