diff --git a/cql3/expr/expression.cc b/cql3/expr/expression.cc index 360e81c52d..57edacc91a 100644 --- a/cql3/expr/expression.cc +++ b/cql3/expr/expression.cc @@ -607,22 +607,6 @@ value_list get_IN_values(const ::shared_ptr& t, size_t k, const query_opti static constexpr bool inclusive = true, exclusive = false; -/// A range of all X such that X op val. -nonwrapping_range to_range(oper_t op, const bytes& val) { - switch (op) { - case oper_t::GT: - return nonwrapping_range::make_starting_with(interval_bound(val, exclusive)); - case oper_t::GTE: - return nonwrapping_range::make_starting_with(interval_bound(val, inclusive)); - case oper_t::LT: - return nonwrapping_range::make_ending_with(interval_bound(val, exclusive)); - case oper_t::LTE: - return nonwrapping_range::make_ending_with(interval_bound(val, inclusive)); - default: - throw std::logic_error(format("to_range: unknown comparison operator {}", op)); - } -} - } // anonymous namespace expression make_conjunction(expression a, expression b) { @@ -660,6 +644,27 @@ std::vector first_multicolumn_bound( } } +template +nonwrapping_range to_range(oper_t op, const T& val) { + static constexpr bool inclusive = true, exclusive = false; + switch (op) { + case oper_t::EQ: + return nonwrapping_range::make_singular(val); + case oper_t::GT: + return nonwrapping_range::make_starting_with(interval_bound(val, exclusive)); + case oper_t::GTE: + return nonwrapping_range::make_starting_with(interval_bound(val, inclusive)); + case oper_t::LT: + return nonwrapping_range::make_ending_with(interval_bound(val, exclusive)); + case oper_t::LTE: + return nonwrapping_range::make_ending_with(interval_bound(val, inclusive)); + default: + throw std::logic_error(format("to_range: unknown comparison operator {}", op)); + } +} + +template nonwrapping_range to_range(oper_t, const clustering_key_prefix&); + value_set possible_lhs_values(const column_definition* cdef, const expression& expr, const query_options& options) { const auto type = cdef ? get_value_comparator(cdef) : long_type.get(); return std::visit(overloaded_functor{ diff --git a/cql3/expr/expression.hh b/cql3/expr/expression.hh index 26cd42df2d..9e356470ca 100644 --- a/cql3/expr/expression.hh +++ b/cql3/expr/expression.hh @@ -131,6 +131,10 @@ extern value_set possible_lhs_values(const column_definition*, const expression& /// Turns value_set into a range, unless it's a multi-valued list (in which case this throws). extern nonwrapping_range to_range(const value_set&); +/// A range of all X such that X op val. +template +nonwrapping_range to_range(oper_t op, const T& val); + /// True iff the index can support the entire expression. extern bool is_supported_by(const expression&, const secondary_index::index&);