From 263749508cccdf7823cb04f9a77512fbce100fb6 Mon Sep 17 00:00:00 2001 From: florijan Date: Wed, 5 Apr 2017 10:34:10 +0200 Subject: [PATCH] Query::Plan - WITH API Reviewers: teon.banek, buda Reviewed By: teon.banek Differential Revision: https://phabricator.memgraph.io/D224 --- src/query/frontend/ast/ast.hpp | 21 +++++++++++++++ src/query/frontend/ast/ast_visitor.hpp | 3 ++- src/query/frontend/logical/operator.cpp | 23 +++++++++++++++++ src/query/frontend/logical/operator.hpp | 34 ++++++++++++++++++++----- 4 files changed, 74 insertions(+), 7 deletions(-) diff --git a/src/query/frontend/ast/ast.hpp b/src/query/frontend/ast/ast.hpp index e9ff0bbf0..f4b66daef 100644 --- a/src/query/frontend/ast/ast.hpp +++ b/src/query/frontend/ast/ast.hpp @@ -550,6 +550,27 @@ class Return : public Clause { Return(int uid) : Clause(uid) {} }; +class With : public Clause { + friend class AstTreeStorage; + + public: + void Accept(TreeVisitorBase &visitor) override { + visitor.Visit(*this); + for (auto &expr : named_expressions_) { + expr->Accept(visitor); + } + if (where_) where_->Accept(visitor); + visitor.PostVisit(*this); + } + + bool distinct_{false}; + std::vector named_expressions_; + Where *where_ = nullptr; + + protected: + With(int uid) : Clause(uid) {} +}; + class Delete : public Clause { friend class AstTreeStorage; diff --git a/src/query/frontend/ast/ast_visitor.hpp b/src/query/frontend/ast/ast_visitor.hpp index 27024e70b..871f32c84 100644 --- a/src/query/frontend/ast/ast_visitor.hpp +++ b/src/query/frontend/ast/ast_visitor.hpp @@ -12,6 +12,7 @@ class PropertyLookup; class Create; class Match; class Return; +class With; class Pattern; class NodeAtom; class EdgeAtom; @@ -47,6 +48,6 @@ using TreeVisitorBase = ::utils::Visitor< DivisionOperator, ModOperator, NotEqualOperator, EqualOperator, LessOperator, GreaterOperator, LessEqualOperator, GreaterEqualOperator, UnaryPlusOperator, UnaryMinusOperator, Identifier, Literal, PropertyLookup, - Create, Match, Return, Pattern, NodeAtom, EdgeAtom, Delete, Where, + Create, Match, Return, With, Pattern, NodeAtom, EdgeAtom, Delete, Where, SetProperty, SetProperties, SetLabels, RemoveProperty, RemoveLabels>; } diff --git a/src/query/frontend/logical/operator.cpp b/src/query/frontend/logical/operator.cpp index 2ec7a5c5d..9a888768d 100644 --- a/src/query/frontend/logical/operator.cpp +++ b/src/query/frontend/logical/operator.cpp @@ -835,5 +835,28 @@ bool ExpandUniquenessFilter::ExpandUniquenessFilterCursor::Pull( template class ExpandUniquenessFilter; template class ExpandUniquenessFilter; +Accumulate::Accumulate(std::shared_ptr input, const std::vector &symbols) : + input_(input), symbols_(symbols) {} + +void Accumulate::Accept(LogicalOperatorVisitor &visitor) { + visitor.Visit(*this); + input_->Accept(visitor); + visitor.PostVisit(*this); +} +std::unique_ptr Accumulate::MakeCursor(GraphDbAccessor &db) { + return std::unique_ptr(); +} + +AdvanceCommand::AdvanceCommand(std::shared_ptr input) : input_(input) {} + +void AdvanceCommand::Accept(LogicalOperatorVisitor &visitor) { + visitor.Visit(*this); + input_->Accept(visitor); + visitor.PostVisit(*this); +} +std::unique_ptr AdvanceCommand::MakeCursor(GraphDbAccessor &db) { + return std::unique_ptr(); +} + } // namespace plan } // namespace query diff --git a/src/query/frontend/logical/operator.hpp b/src/query/frontend/logical/operator.hpp index d33c5f923..03eafe0a9 100644 --- a/src/query/frontend/logical/operator.hpp +++ b/src/query/frontend/logical/operator.hpp @@ -54,14 +54,15 @@ class RemoveProperty; class RemoveLabels; template class ExpandUniquenessFilter; +class Accumulate; +class AdvanceCommand; /** @brief Base class for visitors of @c LogicalOperator class hierarchy. */ -using LogicalOperatorVisitor = - ::utils::Visitor, - ExpandUniquenessFilter>; +using LogicalOperatorVisitor = ::utils::Visitor< + CreateNode, CreateExpand, ScanAll, Expand, NodeFilter, EdgeFilter, Filter, + Produce, Delete, SetProperty, SetProperties, SetLabels, RemoveProperty, + RemoveLabels, ExpandUniquenessFilter, + ExpandUniquenessFilter, Accumulate, AdvanceCommand>; /** @brief Base class for logical operators. * @@ -741,5 +742,26 @@ class ExpandUniquenessFilter : public LogicalOperator { }; }; +class Accumulate : public LogicalOperator { + public: + Accumulate(std::shared_ptr input, const std::vector &symbols); + void Accept(LogicalOperatorVisitor &visitor) override; + std::unique_ptr MakeCursor(GraphDbAccessor &db) override; + + private: + std::shared_ptr input_; + const std::vector symbols_; +}; + +class AdvanceCommand : public LogicalOperator { + public: + AdvanceCommand(std::shared_ptr input); + void Accept(LogicalOperatorVisitor &visitor) override; + std::unique_ptr MakeCursor(GraphDbAccessor &db) override; + + private: + std::shared_ptr input_; +}; + } // namespace plan } // namespace query