cql3: fix empty IN () restriction

Values inside IN () restrictions may be either in a vector _in_values or
a marker (_in_marker or _value). To determine which one is appropriate
we check whether _in_values is empty, which is wrong because IN clause
can be empty (and there is no marker in such case). This is fixed by
using the presence of a marker to determine whether a vector of values
or a marker should be used.

Signed-off-by: Paweł Dziepak <pdziepak@cloudius-systems.com>
This commit is contained in:
Paweł Dziepak
2015-08-13 10:45:27 +02:00
parent 562fa1a726
commit 0afbbb9d44
2 changed files with 4 additions and 3 deletions

View File

@@ -138,7 +138,7 @@ protected:
std::transform(rs.begin(), rs.end(), col_specs.begin(), [] (auto cs) {
return cs->column_specification;
});
if (_in_values.empty()) {
if (_in_marker) {
auto t = to_term(col_specs, get_value(), db, schema->ks_name(), bound_names);
auto as_abstract_marker = static_pointer_cast<abstract_marker>(t);
return ::make_shared<restrictions::multi_column_restriction::IN_with_marker>(schema, rs, as_abstract_marker);

View File

@@ -63,11 +63,12 @@ single_column_relation::new_EQ_restriction(database& db, schema_ptr schema, ::sh
single_column_relation::new_IN_restriction(database& db, schema_ptr schema, ::shared_ptr<variable_specifications> bound_names) {
const column_definition& column_def = to_column_definition(schema, _entity);
auto receivers = to_receivers(schema, column_def);
auto terms = to_terms(receivers, _in_values, db, schema->ks_name(), bound_names);
if (terms.empty()) {
assert(_in_values.empty() || !_value);
if (_value) {
auto term = to_term(receivers, _value, db, schema->ks_name(), bound_names);
return make_shared<single_column_restriction::IN_with_marker>(column_def, dynamic_pointer_cast<lists::marker>(term));
}
auto terms = to_terms(receivers, _in_values, db, schema->ks_name(), bound_names);
return ::make_shared<single_column_restriction::IN_with_values>(column_def, std::move(terms));
}