cql3/expr: Make to_range globally visible

It will be used in statement_restrictions for calculating clustering
bounds.  And it will come in handy elsewhere in the future, I'm sure.

Signed-off-by: Dejan Mircevski <dejan@scylladb.com>
This commit is contained in:
Dejan Mircevski
2021-03-05 17:31:21 -05:00
parent 28b5a372f8
commit 7dfe471b5a
2 changed files with 25 additions and 16 deletions

View File

@@ -607,22 +607,6 @@ value_list get_IN_values(const ::shared_ptr<term>& 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<bytes> to_range(oper_t op, const bytes& val) {
switch (op) {
case oper_t::GT:
return nonwrapping_range<bytes>::make_starting_with(interval_bound(val, exclusive));
case oper_t::GTE:
return nonwrapping_range<bytes>::make_starting_with(interval_bound(val, inclusive));
case oper_t::LT:
return nonwrapping_range<bytes>::make_ending_with(interval_bound(val, exclusive));
case oper_t::LTE:
return nonwrapping_range<bytes>::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<bytes_opt> first_multicolumn_bound(
}
}
template<typename T>
nonwrapping_range<T> to_range(oper_t op, const T& val) {
static constexpr bool inclusive = true, exclusive = false;
switch (op) {
case oper_t::EQ:
return nonwrapping_range<T>::make_singular(val);
case oper_t::GT:
return nonwrapping_range<T>::make_starting_with(interval_bound(val, exclusive));
case oper_t::GTE:
return nonwrapping_range<T>::make_starting_with(interval_bound(val, inclusive));
case oper_t::LT:
return nonwrapping_range<T>::make_ending_with(interval_bound(val, exclusive));
case oper_t::LTE:
return nonwrapping_range<T>::make_ending_with(interval_bound(val, inclusive));
default:
throw std::logic_error(format("to_range: unknown comparison operator {}", op));
}
}
template nonwrapping_range<clustering_key_prefix> 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{

View File

@@ -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<bytes> to_range(const value_set&);
/// A range of all X such that X op val.
template<typename T>
nonwrapping_range<T> 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&);