From add40d4e59861b96295c8a3d2245fd84b8ab4b28 Mon Sep 17 00:00:00 2001 From: Piotr Sarna Date: Fri, 25 Jan 2019 15:01:48 +0100 Subject: [PATCH] cql3: lift infinite bound check if it's supported If the database supports infinite bound range deletions, CQL layer will no longer throw an error indicating that both ranges need to be specified. [bhalevy] Update test_range_deletion_scenarios unit test accordingly. Fixes #432 Signed-off-by: Benny Halevy --- cql3/statements/delete_statement.cc | 9 ++++++--- tests/cql_query_test.cc | 14 ++++---------- 2 files changed, 10 insertions(+), 13 deletions(-) diff --git a/cql3/statements/delete_statement.cc b/cql3/statements/delete_statement.cc index 33bf161d19..e3b6300189 100644 --- a/cql3/statements/delete_statement.cc +++ b/cql3/statements/delete_statement.cc @@ -41,6 +41,7 @@ #include "delete_statement.hh" #include "raw/delete_statement.hh" +#include "database.hh" namespace cql3 { @@ -102,9 +103,11 @@ delete_statement::prepare_internal(database& db, schema_ptr schema, shared_ptrprocess_where_clause(db, _where_clause, std::move(bound_names)); - if (!stmt->restrictions()->get_clustering_columns_restrictions()->has_bound(bound::START) - || !stmt->restrictions()->get_clustering_columns_restrictions()->has_bound(bound::END)) { - throw exceptions::invalid_request_exception("A range deletion operation needs to specify both bounds"); + if (!db.supports_infinite_bound_range_deletions()) { + if (!stmt->restrictions()->get_clustering_columns_restrictions()->has_bound(bound::START) + || !stmt->restrictions()->get_clustering_columns_restrictions()->has_bound(bound::END)) { + throw exceptions::invalid_request_exception("A range deletion operation needs to specify both bounds for clusters without sstable mc format support"); + } } if (!schema->is_compound() && stmt->restrictions()->get_clustering_columns_restrictions()->is_slice()) { throw exceptions::invalid_request_exception("Range deletions on \"compact storage\" schemas are not supported"); diff --git a/tests/cql_query_test.cc b/tests/cql_query_test.cc index 263ce86195..85c7a52d02 100644 --- a/tests/cql_query_test.cc +++ b/tests/cql_query_test.cc @@ -1064,18 +1064,12 @@ SEASTAR_TEST_CASE(test_range_deletion_scenarios) { e.execute_cql(format("insert into cf (p, c, v) values (1, {:d}, 'abc');", i)).get(); } - try { - e.execute_cql("delete from cf where p = 1 and c <= 3").get(); - BOOST_FAIL("should've thrown"); - } catch (...) { } - try { - e.execute_cql("delete from cf where p = 1 and c >= 0").get(); - BOOST_FAIL("should've thrown"); - } catch (...) { } + e.execute_cql("delete from cf where p = 1 and c <= 3").get(); + e.execute_cql("delete from cf where p = 1 and c >= 8").get(); - e.execute_cql("delete from cf where p = 1 and c >= 0 and c <= 3").get(); + e.execute_cql("delete from cf where p = 1 and c >= 0 and c <= 5").get(); auto msg = e.execute_cql("select * from cf").get0(); - assert_that(msg).is_rows().with_size(6); + assert_that(msg).is_rows().with_size(2); e.execute_cql("delete from cf where p = 1 and c > 3 and c < 10").get(); msg = e.execute_cql("select * from cf").get0(); assert_that(msg).is_rows().with_size(0);