From 263e333b1ac669667304d6f52bb366266b077b7c Mon Sep 17 00:00:00 2001 From: "kyle.cao" Date: Fri, 24 Mar 2023 11:06:47 +0800 Subject: [PATCH] move ExprVisitorImpl to common directory and delete storage/ExprVisitorBase small remove Delete ExprVisitorBase small remove --- src/common/expression/CMakeLists.txt | 1 + .../expression}/ExprVisitorImpl.cpp | 6 +- .../expression}/ExprVisitorImpl.h | 31 +++- src/graph/visitor/CMakeLists.txt | 1 - src/graph/visitor/DeducePropsVisitor.h | 2 +- src/graph/visitor/EvaluableExprVisitor.h | 2 +- src/graph/visitor/ExtractFilterExprVisitor.h | 2 +- src/graph/visitor/ExtractGroupSuiteVisitor.h | 2 +- src/graph/visitor/ExtractPropExprVisitor.h | 2 +- src/graph/visitor/FindVisitor.h | 2 +- src/graph/visitor/PropertyTrackerVisitor.h | 2 +- src/graph/visitor/RewriteVisitor.h | 2 +- .../ValidatePatternExpressionVisitor.cpp | 2 +- .../ValidatePatternExpressionVisitor.h | 2 +- src/storage/CMakeLists.txt | 1 - src/storage/ExprVisitorBase.cpp | 150 ------------------ src/storage/ExprVisitorBase.h | 76 --------- src/storage/exec/IndexSelectionNode.h | 6 +- 18 files changed, 40 insertions(+), 252 deletions(-) rename src/{graph/visitor => common/expression}/ExprVisitorImpl.cpp (96%) rename src/{graph/visitor => common/expression}/ExprVisitorImpl.h (61%) delete mode 100644 src/storage/ExprVisitorBase.cpp delete mode 100644 src/storage/ExprVisitorBase.h diff --git a/src/common/expression/CMakeLists.txt b/src/common/expression/CMakeLists.txt index 9818a38c1ab..6bf9f71dc3a 100644 --- a/src/common/expression/CMakeLists.txt +++ b/src/common/expression/CMakeLists.txt @@ -32,6 +32,7 @@ nebula_add_library( ListComprehensionExpression.cpp ReduceExpression.cpp MatchPathPatternExpression.cpp + ExprVisitorImpl.cpp ) nebula_add_subdirectory(test) diff --git a/src/graph/visitor/ExprVisitorImpl.cpp b/src/common/expression/ExprVisitorImpl.cpp similarity index 96% rename from src/graph/visitor/ExprVisitorImpl.cpp rename to src/common/expression/ExprVisitorImpl.cpp index 5a877499401..3f131ba61f6 100644 --- a/src/graph/visitor/ExprVisitorImpl.cpp +++ b/src/common/expression/ExprVisitorImpl.cpp @@ -1,12 +1,11 @@ -/* Copyright (c) 2020 vesoft inc. All rights reserved. +/* Copyright (c) 2023 vesoft inc. All rights reserved. * * This source code is licensed under Apache 2.0 License. */ -#include "graph/visitor/ExprVisitorImpl.h" +#include "common/expression/ExprVisitorImpl.h" namespace nebula { -namespace graph { void ExprVisitorImpl::visit(UnaryExpression *expr) { DCHECK(ok()) << expr->toString(); @@ -210,5 +209,4 @@ void ExprVisitorImpl::visit(MatchPathPatternExpression *expr) { } } -} // namespace graph } // namespace nebula diff --git a/src/graph/visitor/ExprVisitorImpl.h b/src/common/expression/ExprVisitorImpl.h similarity index 61% rename from src/graph/visitor/ExprVisitorImpl.h rename to src/common/expression/ExprVisitorImpl.h index 641bd0da2cf..69700b980c2 100644 --- a/src/graph/visitor/ExprVisitorImpl.h +++ b/src/common/expression/ExprVisitorImpl.h @@ -1,18 +1,34 @@ -/* Copyright (c) 2020 vesoft inc. All rights reserved. +/* Copyright (c) 2023 vesoft inc. All rights reserved. * * This source code is licensed under Apache 2.0 License. */ -#ifndef GRAPH_VISITOR_EXPRVISITORIMPL_H_ -#define GRAPH_VISITOR_EXPRVISITORIMPL_H_ +#ifndef COMMON_VISITOR_EXPRVISITORIMPL_H_ +#define COMMON_VISITOR_EXPRVISITORIMPL_H_ +#include "common/expression/ColumnExpression.h" #include "common/expression/ExprVisitor.h" +#include "common/expression/PropertyExpression.h" +#include "common/expression/VertexExpression.h" namespace nebula { -namespace graph { class ExprVisitorImpl : public ExprVisitor { public: + // leaf expression nodes + void visit(ConstantExpression *) override {} + void visit(LabelExpression *) override{}; + void visit(UUIDExpression *) override{}; + void visit(VariableExpression *) override{}; + void visit(VersionedVariableExpression *) override{}; + void visit(InputPropertyExpression *) override{}; + void visit(VariablePropertyExpression *) override{}; + void visit(DestPropertyExpression *) override{}; + void visit(SourcePropertyExpression *) override{}; + void visit(VertexExpression *) override{}; + void visit(EdgeExpression *) override{}; + void visit(ColumnExpression *) override{}; + // unary expression void visit(UnaryExpression *expr) override; void visit(TypeCastingExpression *expr) override; void visit(LabelAttributeExpression *expr) override; @@ -48,10 +64,11 @@ class ExprVisitorImpl : public ExprVisitor { using ExprVisitor::visit; virtual void visitBinaryExpr(BinaryExpression *expr); - virtual bool ok() const = 0; + virtual bool ok() const { + return true; + } }; -} // namespace graph } // namespace nebula -#endif // GRAPH_VISITOR_EXPRVISITORIMPL_H_ +#endif // COMMON_VISITOR_EXPRVISITORIMPL_H_ diff --git a/src/graph/visitor/CMakeLists.txt b/src/graph/visitor/CMakeLists.txt index 23e6295f592..659ea635f8a 100644 --- a/src/graph/visitor/CMakeLists.txt +++ b/src/graph/visitor/CMakeLists.txt @@ -4,7 +4,6 @@ nebula_add_library( expr_visitor_obj OBJECT - ExprVisitorImpl.cpp DeducePropsVisitor.cpp PropertyTrackerVisitor.cpp DeduceTypeVisitor.cpp diff --git a/src/graph/visitor/DeducePropsVisitor.h b/src/graph/visitor/DeducePropsVisitor.h index 6d6db6acd12..f367ee28e07 100644 --- a/src/graph/visitor/DeducePropsVisitor.h +++ b/src/graph/visitor/DeducePropsVisitor.h @@ -7,8 +7,8 @@ #define GRAPH_VISITOR_DEDUCEPROPSVISITOR_H_ #include "common/base/Status.h" +#include "common/expression/ExprVisitorImpl.h" #include "common/thrift/ThriftTypes.h" -#include "graph/visitor/ExprVisitorImpl.h" namespace nebula { diff --git a/src/graph/visitor/EvaluableExprVisitor.h b/src/graph/visitor/EvaluableExprVisitor.h index 7f5a8b73026..2c82d3dd0c5 100644 --- a/src/graph/visitor/EvaluableExprVisitor.h +++ b/src/graph/visitor/EvaluableExprVisitor.h @@ -6,7 +6,7 @@ #ifndef GRAPH_VISITOR_EVALUABLEEXPRVISITOR_H_ #define GRAPH_VISITOR_EVALUABLEEXPRVISITOR_H_ -#include "graph/visitor/ExprVisitorImpl.h" +#include "common/expression/ExprVisitorImpl.h" namespace nebula { namespace graph { diff --git a/src/graph/visitor/ExtractFilterExprVisitor.h b/src/graph/visitor/ExtractFilterExprVisitor.h index ba04cea70ac..bf3789001c0 100644 --- a/src/graph/visitor/ExtractFilterExprVisitor.h +++ b/src/graph/visitor/ExtractFilterExprVisitor.h @@ -7,7 +7,7 @@ #include -#include "graph/visitor/ExprVisitorImpl.h" +#include "common/expression/ExprVisitorImpl.h" namespace nebula { namespace graph { diff --git a/src/graph/visitor/ExtractGroupSuiteVisitor.h b/src/graph/visitor/ExtractGroupSuiteVisitor.h index debd08f2773..3170caf7853 100644 --- a/src/graph/visitor/ExtractGroupSuiteVisitor.h +++ b/src/graph/visitor/ExtractGroupSuiteVisitor.h @@ -6,8 +6,8 @@ #ifndef GRAPH_VISITOR_EXTRACTGROUPSUITEVISITOR_H_ #define GRAPH_VISITOR_EXTRACTGROUPSUITEVISITOR_H_ +#include "common/expression/ExprVisitorImpl.h" #include "graph/context/ast/CypherAstContext.h" -#include "graph/visitor/ExprVisitorImpl.h" namespace nebula { namespace graph { diff --git a/src/graph/visitor/ExtractPropExprVisitor.h b/src/graph/visitor/ExtractPropExprVisitor.h index 679b8216d47..665d78f634b 100644 --- a/src/graph/visitor/ExtractPropExprVisitor.h +++ b/src/graph/visitor/ExtractPropExprVisitor.h @@ -5,8 +5,8 @@ #ifndef GRAPH_VISITOR_EXTRACTPROPEXPRVISITOR_H_ #define GRAPH_VISITOR_EXTRACTPROPEXPRVISITOR_H_ +#include "common/expression/ExprVisitorImpl.h" #include "graph/context/ValidateContext.h" -#include "graph/visitor/ExprVisitorImpl.h" #include "parser/Clauses.h" namespace nebula { diff --git a/src/graph/visitor/FindVisitor.h b/src/graph/visitor/FindVisitor.h index 7df710e9cbc..c3707014ff5 100644 --- a/src/graph/visitor/FindVisitor.h +++ b/src/graph/visitor/FindVisitor.h @@ -6,8 +6,8 @@ #ifndef GRAPH_VISITOR_FINDVISITOR_H_ #define GRAPH_VISITOR_FINDVISITOR_H_ +#include "common/expression/ExprVisitorImpl.h" #include "common/expression/Expression.h" -#include "graph/visitor/ExprVisitorImpl.h" namespace nebula { namespace graph { diff --git a/src/graph/visitor/PropertyTrackerVisitor.h b/src/graph/visitor/PropertyTrackerVisitor.h index daabb015a24..c97cb935dec 100644 --- a/src/graph/visitor/PropertyTrackerVisitor.h +++ b/src/graph/visitor/PropertyTrackerVisitor.h @@ -7,8 +7,8 @@ #define GRAPH_VISITOR_PROPERTYTRACKERVISITOR_H #include "common/base/Status.h" +#include "common/expression/ExprVisitorImpl.h" #include "common/thrift/ThriftTypes.h" -#include "graph/visitor/ExprVisitorImpl.h" namespace nebula { diff --git a/src/graph/visitor/RewriteVisitor.h b/src/graph/visitor/RewriteVisitor.h index d6982063ba5..1accc008eb7 100644 --- a/src/graph/visitor/RewriteVisitor.h +++ b/src/graph/visitor/RewriteVisitor.h @@ -8,7 +8,7 @@ #include -#include "graph/visitor/ExprVisitorImpl.h" +#include "common/expression/ExprVisitorImpl.h" namespace nebula { namespace graph { diff --git a/src/graph/visitor/ValidatePatternExpressionVisitor.cpp b/src/graph/visitor/ValidatePatternExpressionVisitor.cpp index dd5385554cc..83c257a43da 100644 --- a/src/graph/visitor/ValidatePatternExpressionVisitor.cpp +++ b/src/graph/visitor/ValidatePatternExpressionVisitor.cpp @@ -3,7 +3,7 @@ // This source code is licensed under Apache 2.0 License. #include "graph/visitor/ValidatePatternExpressionVisitor.h" -#include "ExprVisitorImpl.h" +#include "common/expression/ExprVisitorImpl.h" #include "graph/context/ValidateContext.h" namespace nebula { diff --git a/src/graph/visitor/ValidatePatternExpressionVisitor.h b/src/graph/visitor/ValidatePatternExpressionVisitor.h index 72bdf2b5945..142d1070cd1 100644 --- a/src/graph/visitor/ValidatePatternExpressionVisitor.h +++ b/src/graph/visitor/ValidatePatternExpressionVisitor.h @@ -4,8 +4,8 @@ #pragma once +#include "common/expression/ExprVisitorImpl.h" #include "common/expression/Expression.h" -#include "graph/visitor/ExprVisitorImpl.h" namespace nebula { namespace graph { diff --git a/src/storage/CMakeLists.txt b/src/storage/CMakeLists.txt index 83779b3f6e8..e0c29e8d014 100644 --- a/src/storage/CMakeLists.txt +++ b/src/storage/CMakeLists.txt @@ -34,7 +34,6 @@ nebula_add_library( nebula_add_library( graph_storage_service_handler OBJECT GraphStorageServiceHandler.cpp - ExprVisitorBase.cpp context/StorageExpressionContext.cpp mutate/AddVerticesProcessor.cpp mutate/DeleteVerticesProcessor.cpp diff --git a/src/storage/ExprVisitorBase.cpp b/src/storage/ExprVisitorBase.cpp deleted file mode 100644 index d2f286b1fa2..00000000000 --- a/src/storage/ExprVisitorBase.cpp +++ /dev/null @@ -1,150 +0,0 @@ -/* Copyright (c) 2021 vesoft inc. All rights reserved. - * - * This source code is licensed under Apache 2.0 License. - */ -#include "storage/ExprVisitorBase.h" -namespace nebula { -namespace storage { -void ExprVisitorBase::visit(ConstantExpression *expr) { - UNUSED(expr); -} -void ExprVisitorBase::visit(UnaryExpression *expr) { - expr->operand()->accept(this); -} -void ExprVisitorBase::visit(TypeCastingExpression *expr) { - expr->operand()->accept(this); -} -void ExprVisitorBase::visit(LabelExpression *expr) { - fatal(expr); -} -void ExprVisitorBase::visit(LabelAttributeExpression *expr) { - fatal(expr); -} -// binary expression -void ExprVisitorBase::visit(ArithmeticExpression *expr) { - expr->left()->accept(this); - expr->right()->accept(this); -} -void ExprVisitorBase::visit(RelationalExpression *expr) { - expr->left()->accept(this); - expr->right()->accept(this); -} -void ExprVisitorBase::visit(SubscriptExpression *expr) { - expr->left()->accept(this); - expr->right()->accept(this); -} -void ExprVisitorBase::visit(AttributeExpression *) {} -void ExprVisitorBase::visit(LogicalExpression *expr) { - for (auto operand : expr->operands()) { - operand->accept(this); - } -} -// function call -void ExprVisitorBase::visit(FunctionCallExpression *expr) { - for (auto arg : expr->args()->args()) { - arg->accept(this); - } -} -void ExprVisitorBase::visit(AggregateExpression *expr) { - fatal(expr); -} -void ExprVisitorBase::visit(UUIDExpression *expr) { - UNUSED(expr); -} -// variable expression -void ExprVisitorBase::visit(VariableExpression *expr) { - fatal(expr); -} -void ExprVisitorBase::visit(VersionedVariableExpression *expr) { - fatal(expr); -} -// container expression -void ExprVisitorBase::visit(ListExpression *expr) { - for (auto item : expr->items()) { - item->accept(this); - } -} -void ExprVisitorBase::visit(SetExpression *expr) { - for (auto item : expr->items()) { - item->accept(this); - } -} -void ExprVisitorBase::visit(MapExpression *expr) { - UNUSED(expr); -} -// property Expression -void ExprVisitorBase::visit(TagPropertyExpression *expr) { - UNUSED(expr); -} -void ExprVisitorBase::visit(EdgePropertyExpression *expr) { - UNUSED(expr); -} -void ExprVisitorBase::visit(InputPropertyExpression *expr) { - UNUSED(expr); -} -void ExprVisitorBase::visit(VariablePropertyExpression *expr) { - UNUSED(expr); -} -void ExprVisitorBase::visit(DestPropertyExpression *expr) { - UNUSED(expr); -} -void ExprVisitorBase::visit(SourcePropertyExpression *expr) { - UNUSED(expr); -} -void ExprVisitorBase::visit(EdgeSrcIdExpression *expr) { - UNUSED(expr); -} -void ExprVisitorBase::visit(EdgeTypeExpression *expr) { - UNUSED(expr); -} -void ExprVisitorBase::visit(EdgeRankExpression *expr) { - UNUSED(expr); -} -void ExprVisitorBase::visit(EdgeDstIdExpression *expr) { - UNUSED(expr); -} -void ExprVisitorBase::visit(LabelTagPropertyExpression *expr) { - UNUSED(expr); -} -// vertex/edge expression -void ExprVisitorBase::visit(VertexExpression *expr) { - UNUSED(expr); -} -void ExprVisitorBase::visit(EdgeExpression *expr) { - UNUSED(expr); -} -// case expression -void ExprVisitorBase::visit(CaseExpression *expr) { - UNUSED(expr); -} -// path build expression -void ExprVisitorBase::visit(PathBuildExpression *expr) { - fatal(expr); -} -// column expression -void ExprVisitorBase::visit(ColumnExpression *expr) { - fatal(expr); -} -// predicate expression -void ExprVisitorBase::visit(PredicateExpression *expr) { - fatal(expr); -} -// list comprehension expression -void ExprVisitorBase::visit(ListComprehensionExpression *expr) { - fatal(expr); -} -// reduce expression -void ExprVisitorBase::visit(ReduceExpression *expr) { - fatal(expr); -} -// subscript range expression -void ExprVisitorBase::visit(SubscriptRangeExpression *expr) { - fatal(expr); -} - -void ExprVisitorBase::visit(MatchPathPatternExpression *expr) { - fatal(expr); -} - -} // namespace storage -} // namespace nebula diff --git a/src/storage/ExprVisitorBase.h b/src/storage/ExprVisitorBase.h deleted file mode 100644 index 4d4975be4fa..00000000000 --- a/src/storage/ExprVisitorBase.h +++ /dev/null @@ -1,76 +0,0 @@ -/* Copyright (c) 2021 vesoft inc. All rights reserved. - * - * This source code is licensed under Apache 2.0 License. - */ - -#ifndef STORAGE_EXPRVISITORBASE_H -#define STORAGE_EXPRVISITORBASE_H -#include "common/expression/ExprVisitor.h" -namespace nebula { -namespace storage { - -class ExprVisitorBase : public ::nebula::ExprVisitor { - public: - void visit(ConstantExpression *expr) override; - void visit(UnaryExpression *expr) override; - void visit(TypeCastingExpression *expr) override; - void visit(LabelExpression *expr) override; - void visit(LabelAttributeExpression *expr) override; - // binary expression - void visit(ArithmeticExpression *expr) override; - void visit(RelationalExpression *expr) override; - void visit(SubscriptExpression *expr) override; - void visit(AttributeExpression *expr) override; - void visit(LogicalExpression *expr) override; - // function call - void visit(FunctionCallExpression *expr) override; - void visit(AggregateExpression *expr) override; - void visit(UUIDExpression *expr) override; - // variable expression - void visit(VariableExpression *expr) override; - void visit(VersionedVariableExpression *expr) override; - // container expression - void visit(ListExpression *expr) override; - void visit(SetExpression *expr) override; - void visit(MapExpression *expr) override; - // property Expression - void visit(LabelTagPropertyExpression *expr) override; - void visit(TagPropertyExpression *expr) override; - void visit(EdgePropertyExpression *expr) override; - void visit(InputPropertyExpression *expr) override; - void visit(VariablePropertyExpression *expr) override; - void visit(DestPropertyExpression *expr) override; - void visit(SourcePropertyExpression *expr) override; - void visit(EdgeSrcIdExpression *expr) override; - void visit(EdgeTypeExpression *expr) override; - void visit(EdgeRankExpression *expr) override; - void visit(EdgeDstIdExpression *expr) override; - // vertex/edge expression - void visit(VertexExpression *expr) override; - void visit(EdgeExpression *expr) override; - // case expression - void visit(CaseExpression *expr) override; - // path build expression - void visit(PathBuildExpression *expr) override; - // column expression - void visit(ColumnExpression *expr) override; - // predicate expression - void visit(PredicateExpression *expr) override; - // list comprehension expression - void visit(ListComprehensionExpression *expr) override; - // reduce expression - void visit(ReduceExpression *expr) override; - // subscript range expression - void visit(SubscriptRangeExpression *expr) override; - // match pattern expression - void visit(MatchPathPatternExpression *expr) override; - - private: - using ::nebula::ExprVisitor::visit; - inline void fatal(Expression *expr) { - LOG(FATAL) << "Unexpect expression kind " << static_cast(expr->kind()) << " at storage"; - } -}; -} // namespace storage -} // namespace nebula -#endif diff --git a/src/storage/exec/IndexSelectionNode.h b/src/storage/exec/IndexSelectionNode.h index 9cb73711a3c..ba6cec28b9a 100644 --- a/src/storage/exec/IndexSelectionNode.h +++ b/src/storage/exec/IndexSelectionNode.h @@ -6,9 +6,9 @@ #define STORAGE_EXEC_INDEXSELECTIONNODE_H #include "common/context/ExpressionContext.h" +#include "common/expression/ExprVisitorImpl.h" #include "common/expression/Expression.h" #include "folly/container/F14Map.h" -#include "storage/ExprVisitorBase.h" #include "storage/exec/IndexExprContext.h" #include "storage/exec/IndexNode.h" namespace nebula { @@ -65,7 +65,7 @@ class IndexSelectionNode : public IndexNode { std::unique_ptr ctx_; }; -class SelectionExprVisitor : public ExprVisitorBase { +class SelectionExprVisitor : public ExprVisitorImpl { public: void visit(EdgeSrcIdExpression *expr) override { requiredColumns_.insert(expr->prop()); @@ -96,7 +96,7 @@ class SelectionExprVisitor : public ExprVisitorBase { } private: - using ExprVisitorBase::visit; + using ExprVisitorImpl::visit; Set requiredColumns_; ::nebula::cpp2::ErrorCode code_; };