diff --git a/src/query/plan/operator.cpp b/src/query/plan/operator.cpp index 26ba8de0b..ca18161b4 100644 --- a/src/query/plan/operator.cpp +++ b/src/query/plan/operator.cpp @@ -294,17 +294,17 @@ std::unique_ptr ScanAllByLabelPropertyRange::MakeCursor( auto vertices = [this, &db, is_less](Frame &frame, const SymbolTable &symbol_table) { ExpressionEvaluator evaluator(frame, symbol_table, db, graph_view_); - auto lower_val = lower_bound_ ? lower_bound_->expression->Accept(evaluator) + auto lower_val = lower_bound_ ? lower_bound_->value()->Accept(evaluator) : TypedValue::Null; - auto upper_val = upper_bound_ ? upper_bound_->expression->Accept(evaluator) + auto upper_val = upper_bound_ ? upper_bound_->value()->Accept(evaluator) : TypedValue::Null; return iter::filter( [this, lower_val, upper_val, is_less](const VertexAccessor &vertex) { TypedValue value = vertex.PropsAt(property_); debug_assert(!value.IsNull(), "Unexpected property with Null value"); - if (lower_bound_ && is_less(value, lower_val, lower_bound_->type)) + if (lower_bound_ && is_less(value, lower_val, lower_bound_->type())) return false; - if (upper_bound_ && is_less(upper_val, value, upper_bound_->type)) + if (upper_bound_ && is_less(upper_val, value, upper_bound_->type())) return false; return true; }, diff --git a/src/query/plan/operator.hpp b/src/query/plan/operator.hpp index 5d0256be1..c7ef38b50 100644 --- a/src/query/plan/operator.hpp +++ b/src/query/plan/operator.hpp @@ -14,6 +14,7 @@ #include "query/common.hpp" #include "query/exceptions.hpp" #include "query/frontend/semantic/symbol_table.hpp" +#include "utils/bound.hpp" #include "utils/hashing/fnv.hpp" #include "utils/visitor.hpp" @@ -353,20 +354,8 @@ class ScanAllByLabel : public ScanAll { */ class ScanAllByLabelPropertyRange : public ScanAll { public: - /** Defines a bounding value for a range. */ - struct Bound { - /** - * Determines whether the value of bound expression should be included or - * excluded. - */ - enum class Type { INCLUSIVE, EXCLUSIVE }; - - /** Expression which when evaluated will produce a value for the bound. */ - Expression *expression; - /** Whether the bound is inclusive or exclusive. */ - Type type; - }; - + /** Bound with expression which when evaluated produces the bound value. */ + using Bound = utils::Bound; /** * Constructs the operator for given label and property value in range * (inclusive). diff --git a/src/utils/border.hpp b/src/utils/border.hpp deleted file mode 100644 index aab835a0f..000000000 --- a/src/utils/border.hpp +++ /dev/null @@ -1,59 +0,0 @@ -#pragma once - -#include "utils/option.hpp" -#include "utils/total_ordering.hpp" - -// Defines Including as [ and Excluding < for ranges. -enum BorderType { - Including = 0, - Excluding = 1, -}; - -// If key is not present he is both the largest and the smallest of the keys. -template -class Border { - public: - Border() : key(Option()), type(Including) {} - Border(T Tey, BorderType type) : key(Option(std::move(key))), type(type) {} - - // Border(Border &other) = default; - Border(Border &other) = default; - Border(Border &&other) = default; - - Border &operator=(Border &&other) = default; - Border &operator=(Border &other) = default; - - friend bool operator<(const Border &a, const T &other) { - return !a.key.is_present() || - (a.type == Excluding && a.key.get() <= other) || - (a.type == Including && a.key.get() < other); - } - - friend bool operator==(const Border &a, const T &other) { - return a.type == Including && a.key.is_present() && a.key.get() == other; - } - - friend bool operator>(const Border &a, const T &other) { - return !a.key.is_present() || - (a.type == Excluding && a.key.get() >= other) || - (a.type == Including && a.key.get() > other); - } - - friend bool operator!=(const Border &a, const T &b) { return !(a == b); } - - friend bool operator<=(const Border &a, const T &b) { - return a < b || a == b; - } - - friend bool operator>=(const Border &a, const T &b) { - return a > b || a == b; - } - - Option key; - BorderType type; -}; - -template -auto make_inf_border() { - return Border(); -} diff --git a/src/utils/bound.hpp b/src/utils/bound.hpp new file mode 100644 index 000000000..7ef896f12 --- /dev/null +++ b/src/utils/bound.hpp @@ -0,0 +1,35 @@ +#pragma once + +namespace utils { + +/** + * Determines whether the value of bound expression should be included or + * excluded. + */ +enum class BoundType { INCLUSIVE, EXCLUSIVE }; + +/** Defines a bounding value for a range. */ +template +class Bound { + public: + using Type = BoundType; + + Bound(TValue value, Type type) : value_(value), type_(type) {} + + Bound(const Bound &other) = default; + Bound(Bound &&other) = default; + + Bound &operator=(const Bound &other) = default; + Bound &operator=(Bound &&other) = default; + + /** Value for the bound. */ + const auto &value() const { return value_; } + /** Whether the bound is inclusive or exclusive. */ + auto type() const { return type_; } + + private: + TValue value_; + Type type_; +}; + +} // namespace utils