From 2b7ffd57fba293da2a5f8ce62a2883da5703c5bf Mon Sep 17 00:00:00 2001 From: Jan Ciolek Date: Fri, 15 Jul 2022 14:21:08 +0200 Subject: [PATCH] cql3: Return an expression in get_clustering_columns_restrctions() get_clustering_columns_restrctions() used to return a shared pointer to the clustering_restrictions class. Now everything is being converted to expression, so it should return an expression as well. Signed-off-by: Jan Ciolek --- cql3/restrictions/statement_restrictions.hh | 4 ++-- cql3/selection/selection.cc | 6 +++--- cql3/statements/delete_statement.cc | 2 +- cql3/statements/modification_statement.cc | 12 ++++++------ cql3/statements/select_statement.cc | 4 ++-- db/view/view.cc | 4 ++-- 6 files changed, 16 insertions(+), 16 deletions(-) diff --git a/cql3/restrictions/statement_restrictions.hh b/cql3/restrictions/statement_restrictions.hh index 4c4a7a78b1..2e51ea7553 100644 --- a/cql3/restrictions/statement_restrictions.hh +++ b/cql3/restrictions/statement_restrictions.hh @@ -183,8 +183,8 @@ public: return _partition_key_restrictions; } - ::shared_ptr get_clustering_columns_restrictions() const { - return _clustering_columns_restrictions; + const expr::expression& get_clustering_columns_restrictions() const { + return _new_clustering_columns_restrictions; } bool has_token_restrictions() const { diff --git a/cql3/selection/selection.cc b/cql3/selection/selection.cc index b20fbb237c..32468863d0 100644 --- a/cql3/selection/selection.cc +++ b/cql3/selection/selection.cc @@ -423,13 +423,13 @@ bool result_set_builder::restrictions_filter::do_filter(const selection& selecti return false; } - auto clustering_columns_restrictions = _restrictions->get_clustering_columns_restrictions(); - if (dynamic_pointer_cast(clustering_columns_restrictions)) { + const expr::expression& clustering_columns_restrictions = _restrictions->get_clustering_columns_restrictions(); + if (expr::contains_multi_column_restriction(clustering_columns_restrictions)) { clustering_key_prefix ckey = clustering_key_prefix::from_exploded(clustering_key); // FIXME: push to upper layer so it happens once per row auto static_and_regular_columns = expr::get_non_pk_values(selection, static_row, row); return expr::is_satisfied_by( - clustering_columns_restrictions->expression, + clustering_columns_restrictions, expr::evaluation_inputs{ .partition_key = &partition_key, .clustering_key = &clustering_key, diff --git a/cql3/statements/delete_statement.cc b/cql3/statements/delete_statement.cc index 80bf1e7aea..88bd72c503 100644 --- a/cql3/statements/delete_statement.cc +++ b/cql3/statements/delete_statement.cc @@ -78,7 +78,7 @@ delete_statement::prepare_internal(data_dictionary::database db, schema_ptr sche } prepare_conditions(db, *schema, ctx, *stmt); stmt->process_where_clause(db, _where_clause, ctx); - if (has_slice(stmt->restrictions().get_clustering_columns_restrictions()->expression)) { + if (has_slice(stmt->restrictions().get_clustering_columns_restrictions())) { if (!schema->is_compound()) { throw exceptions::invalid_request_exception("Range deletions on \"compact storage\" schemas are not supported"); } diff --git a/cql3/statements/modification_statement.cc b/cql3/statements/modification_statement.cc index ba3f6d72e7..87f430ce2f 100644 --- a/cql3/statements/modification_statement.cc +++ b/cql3/statements/modification_statement.cc @@ -399,10 +399,10 @@ modification_statement::process_where_clause(data_dictionary::database db, std:: | boost::adaptors::transformed(std::mem_fn(&column_definition::name_as_text))); throw exceptions::invalid_request_exception(format("Invalid where clause contains non PRIMARY KEY columns: {}", column_names)); } - auto ck_restrictions = _restrictions->get_clustering_columns_restrictions(); - if (has_slice(ck_restrictions->expression) && !allow_clustering_key_slices()) { + const expr::expression& ck_restrictions = _restrictions->get_clustering_columns_restrictions(); + if (has_slice(ck_restrictions) && !allow_clustering_key_slices()) { throw exceptions::invalid_request_exception( - format("Invalid operator in where clause {}", to_string(ck_restrictions->expression))); + format("Invalid operator in where clause {}", to_string(ck_restrictions))); } if (_restrictions->has_unrestricted_clustering_columns() && !applies_only_to_static_columns() && !s->is_dense()) { // Tomek: Origin had "&& s->comparator->is_composite()" in the condition below. @@ -415,13 +415,13 @@ modification_statement::process_where_clause(data_dictionary::database db, std:: // Those tables don't have clustering columns so we wouldn't reach this code, thus // the check seems redundant. if (require_full_clustering_key()) { - auto& col = s->column_at(column_kind::clustering_key, ck_restrictions->size()); + auto& col = s->column_at(column_kind::clustering_key, _restrictions->clustering_columns_restrictions_size()); throw exceptions::invalid_request_exception(format("Missing mandatory PRIMARY KEY part {}", col.name_as_text())); } // In general, we can't modify specific columns if not all clustering columns have been specified. // However, if we modify only static columns, it's fine since we won't really use the prefix anyway. - if (!has_slice(ck_restrictions->expression)) { - auto& col = s->column_at(column_kind::clustering_key, ck_restrictions->size()); + if (!has_slice(ck_restrictions)) { + auto& col = s->column_at(column_kind::clustering_key, _restrictions->clustering_columns_restrictions_size()); for (auto&& op : _column_operations) { if (!op->column.is_static()) { throw exceptions::invalid_request_exception(format("Primary key column '{}' must be specified in order to modify column '{}'", diff --git a/cql3/statements/select_statement.cc b/cql3/statements/select_statement.cc index 6e61c5cb27..e9b0bc371d 100644 --- a/cql3/statements/select_statement.cc +++ b/cql3/statements/select_statement.cc @@ -1944,12 +1944,12 @@ static bool needs_allow_filtering_anyway( if (strict_allow_filtering == flag_t::FALSE) { return false; } - const auto& ck_restrictions = *restrictions.get_clustering_columns_restrictions(); + const auto& ck_restrictions = restrictions.get_clustering_columns_restrictions(); const auto& pk_restrictions = restrictions.get_partition_key_restrictions(); // Even if no filtering happens on the coordinator, we still warn about poor performance when partition // slice is defined but in potentially unlimited number of partitions (see #7608). if ((expr::is_empty_restriction(pk_restrictions) || has_token(pk_restrictions)) // Potentially unlimited partitions. - && !ck_restrictions.empty() // Slice defined. + && !expr::is_empty_restriction(ck_restrictions) // Slice defined. && !restrictions.uses_secondary_indexing()) { // Base-table is used. (Index-table use always limits partitions.) if (strict_allow_filtering == flag_t::WARN) { warnings.emplace_back("This query should use ALLOW FILTERING and will be rejected in future versions."); diff --git a/db/view/view.cc b/db/view/view.cc index 0a5968347c..2f1dad655d 100644 --- a/db/view/view.cc +++ b/db/view/view.cc @@ -256,7 +256,7 @@ bool partition_key_matches(const schema& base, const view_info& view, const dht: } bool clustering_prefix_matches(const schema& base, const view_info& view, const partition_key& key, const clustering_key_prefix& ck) { - const auto r = view.select_statement().get_restrictions()->get_clustering_columns_restrictions(); + const cql3::expr::expression& r = view.select_statement().get_restrictions()->get_clustering_columns_restrictions(); std::vector exploded_pk = key.explode(); std::vector exploded_ck = ck.explode(); std::vector ck_columns; @@ -269,7 +269,7 @@ bool clustering_prefix_matches(const schema& base, const view_info& view, const auto dummy_options = cql3::query_options({ }); // FIXME: pass nullptrs for some of theses dummies return cql3::expr::is_satisfied_by( - r->expression, + r, cql3::expr::evaluation_inputs{ .partition_key = &exploded_pk, .clustering_key = &exploded_ck,