diff --git a/cql3/Cql.g b/cql3/Cql.g index 6c784204fc..e7b00db6ac 100644 --- a/cql3/Cql.g +++ b/cql3/Cql.g @@ -147,8 +147,11 @@ using uexpression = uninitialized; listener_type* listener; - std::vector<::shared_ptr> _bind_variables; - // index into _bind_variables + // Keeps the names of all bind variables. For bind variables without a name ('?'), the name is nullptr. + // Maps bind_index -> name. + std::vector<::shared_ptr> _bind_variable_names; + + // Maps name -> bind_index for all named bind variables. std::unordered_map _named_bind_variables_indexes; std::vector> _missing_tokens; @@ -172,8 +175,8 @@ using uexpression = uninitialized; if (name && _named_bind_variables_indexes.contains(*name)) { return bind_variable{_named_bind_variables_indexes[*name]}; } - auto marker = bind_variable{_bind_variables.size()}; - _bind_variables.push_back(name); + auto marker = bind_variable{_bind_variable_names.size()}; + _bind_variable_names.push_back(name); if (name) { _named_bind_variables_indexes[*name] = marker.bind_index; } @@ -321,7 +324,7 @@ query returns [std::unique_ptr stmnt] ; cqlStatement returns [std::unique_ptr stmt] - @after{ if (stmt) { stmt->set_bound_variables(_bind_variables); } } + @after{ if (stmt) { stmt->set_bound_variables(_bind_variable_names); } } : st1= selectStatement { $stmt = std::move(st1); } | st2= insertStatement { $stmt = std::move(st2); } | st3= updateStatement { $stmt = std::move(st3); } diff --git a/cql3/prepare_context.cc b/cql3/prepare_context.cc index 8e02f6f549..eb8285b5f0 100644 --- a/cql3/prepare_context.cc +++ b/cql3/prepare_context.cc @@ -19,11 +19,11 @@ size_t prepare_context::bound_variables_size() const { } const std::vector>& prepare_context::get_variable_specifications() const & { - return _specs; + return _variable_specs; } std::vector> prepare_context::get_variable_specifications() && { - return std::move(_specs); + return std::move(_variable_specs); } std::vector prepare_context::get_partition_key_bind_indexes(const schema& schema) const { @@ -48,12 +48,12 @@ std::vector prepare_context::get_partition_key_bind_indexes(const sche void prepare_context::add_variable_specification(int32_t bind_index, lw_shared_ptr spec) { auto name = _variable_names[bind_index]; - if (_specs[bind_index]) { + if (_variable_specs[bind_index]) { // If the same variable is used in multiple places, check that the types are compatible - if (&spec->type->without_reversed() != &_specs[bind_index]->type->without_reversed()) { + if (&spec->type->without_reversed() != &_variable_specs[bind_index]->type->without_reversed()) { throw exceptions::invalid_request_exception( fmt::format("variable :{} has type {} which doesn't match {}", - *name, _specs[bind_index]->type->as_cql3_type(), spec->name)); + *name, _variable_specs[bind_index]->type->as_cql3_type(), spec->name)); } } _target_columns[bind_index] = spec; @@ -61,16 +61,16 @@ void prepare_context::add_variable_specification(int32_t bind_index, lw_shared_p if (name) { spec = make_lw_shared(spec->ks_name, spec->cf_name, name, spec->type); } - _specs[bind_index] = spec; + _variable_specs[bind_index] = spec; } -void prepare_context::set_bound_variables(const std::vector>& prepare_meta) { - _variable_names = prepare_meta; - _specs.clear(); +void prepare_context::set_bound_variables(const std::vector>& bind_variable_names) { + _variable_names = bind_variable_names; + _variable_specs.clear(); _target_columns.clear(); - const size_t bn_size = prepare_meta.size(); - _specs.resize(bn_size); + const size_t bn_size = bind_variable_names.size(); + _variable_specs.resize(bn_size); _target_columns.resize(bn_size); } diff --git a/cql3/prepare_context.hh b/cql3/prepare_context.hh index 603c600187..fc1bf18cb0 100644 --- a/cql3/prepare_context.hh +++ b/cql3/prepare_context.hh @@ -33,9 +33,17 @@ namespace functions { class function_call; } */ class prepare_context final { private: + // Keeps names of all the bind variables. For bind variables without a name ('?'), the name is nullptr. + // Maps bind_index -> name. std::vector> _variable_names; - std::vector> _specs; + + // Keeps column_specification for every bind_index. column_specification describes the name and type of this variable. + // It's different from _target_columns because it describes the name of this variable, not the target column. + std::vector> _variable_specs; + + // The column to which bind variable with a given bind_index will be assigned to. std::vector> _target_columns; + // A list of pointers to prepared `function_call` cache ids, that // participate in partition key ranges computation within an LWT statement. std::vector<::shared_ptr>> _pk_function_calls_cache_ids; @@ -61,7 +69,7 @@ public: void add_variable_specification(int32_t bind_index, lw_shared_ptr spec); - void set_bound_variables(const std::vector>& prepare_meta); + void set_bound_variables(const std::vector>& bind_variable_names); void clear_pk_function_calls_cache();