diff --git a/src/optimizer/rule/EdgeIndexFullScanRule.cpp b/src/optimizer/rule/EdgeIndexFullScanRule.cpp index 52d0c5a93..3a583b195 100644 --- a/src/optimizer/rule/EdgeIndexFullScanRule.cpp +++ b/src/optimizer/rule/EdgeIndexFullScanRule.cpp @@ -5,6 +5,12 @@ */ #include "optimizer/rule/EdgeIndexFullScanRule.h" +#include "optimizer/OptContext.h" +#include "planner/plan/Query.h" +#include "planner/plan/Scan.h" + +using nebula::graph::EdgeIndexFullScan; +using nebula::graph::IndexScan; using Kind = nebula::graph::PlanNode::Kind; @@ -27,5 +33,10 @@ std::string EdgeIndexFullScanRule::toString() const { return "EdgeIndexFullScanRule"; } +IndexScan* EdgeIndexFullScanRule::scan(OptContext* ctx, const graph::PlanNode* node) const { + auto scan = static_cast(node); + return EdgeIndexFullScan::make(ctx->qctx(), nullptr, scan->edgeType()); +} + } // namespace opt } // namespace nebula diff --git a/src/optimizer/rule/EdgeIndexFullScanRule.h b/src/optimizer/rule/EdgeIndexFullScanRule.h index c0004e3a3..508941c56 100644 --- a/src/optimizer/rule/EdgeIndexFullScanRule.h +++ b/src/optimizer/rule/EdgeIndexFullScanRule.h @@ -14,11 +14,12 @@ namespace opt { class EdgeIndexFullScanRule final : public IndexFullScanBaseRule { public: - const Pattern &pattern() const override; + const Pattern& pattern() const override; std::string toString() const override; private: EdgeIndexFullScanRule(); + graph::IndexScan* scan(OptContext* ctx, const graph::PlanNode* node) const override; static std::unique_ptr kInstance; }; diff --git a/src/optimizer/rule/IndexFullScanBaseRule.cpp b/src/optimizer/rule/IndexFullScanBaseRule.cpp index 980374283..b568d8908 100644 --- a/src/optimizer/rule/IndexFullScanBaseRule.cpp +++ b/src/optimizer/rule/IndexFullScanBaseRule.cpp @@ -7,6 +7,7 @@ #include "optimizer/rule/IndexFullScanBaseRule.h" #include "common/interface/gen-cpp2/storage_types.h" +#include "context/QueryContext.h" #include "optimizer/OptContext.h" #include "optimizer/OptGroup.h" #include "optimizer/OptRule.h" @@ -58,7 +59,7 @@ StatusOr IndexFullScanBaseRule::transform(OptContext* ctx, ictx.set_index_id(idxId); idxCtxs.emplace_back(std::move(ictx)); - auto scanNode = static_cast(scan->clone()); + auto scanNode = this->scan(ctx, scan); OptimizerUtils::copyIndexScanData(scan, scanNode); scanNode->setOutputVar(scan->outputVar()); scanNode->setColNames(scan->colNames()); diff --git a/src/optimizer/rule/IndexFullScanBaseRule.h b/src/optimizer/rule/IndexFullScanBaseRule.h index beebc1a34..ff4b9c225 100644 --- a/src/optimizer/rule/IndexFullScanBaseRule.h +++ b/src/optimizer/rule/IndexFullScanBaseRule.h @@ -10,6 +10,12 @@ #include "optimizer/OptRule.h" namespace nebula { +class PlanNode; + +namespace graph { +class IndexScan; +} // namespace graph + namespace opt { class IndexFullScanBaseRule : public OptRule { @@ -17,6 +23,9 @@ class IndexFullScanBaseRule : public OptRule { bool match(OptContext *ctx, const MatchedResult &matched) const override; StatusOr transform(OptContext *ctx, const MatchedResult &matched) const override; + +protected: + virtual graph::IndexScan *scan(OptContext *ctx, const graph::PlanNode *node) const = 0; }; } // namespace opt diff --git a/src/optimizer/rule/TagIndexFullScanRule.cpp b/src/optimizer/rule/TagIndexFullScanRule.cpp index 13e458448..e601195c5 100644 --- a/src/optimizer/rule/TagIndexFullScanRule.cpp +++ b/src/optimizer/rule/TagIndexFullScanRule.cpp @@ -5,6 +5,8 @@ */ #include "optimizer/rule/TagIndexFullScanRule.h" +#include "optimizer/OptContext.h" +#include "planner/plan/Scan.h" using Kind = nebula::graph::PlanNode::Kind; @@ -27,5 +29,10 @@ std::string TagIndexFullScanRule::toString() const { return "TagIndexFullScanRule"; } +graph::IndexScan* TagIndexFullScanRule::scan(OptContext* ctx, const graph::PlanNode* node) const { + auto scan = static_cast(node); + return graph::TagIndexFullScan::make(ctx->qctx(), nullptr, scan->tagName()); +} + } // namespace opt } // namespace nebula diff --git a/src/optimizer/rule/TagIndexFullScanRule.h b/src/optimizer/rule/TagIndexFullScanRule.h index 90f7e9784..70247f17e 100644 --- a/src/optimizer/rule/TagIndexFullScanRule.h +++ b/src/optimizer/rule/TagIndexFullScanRule.h @@ -14,11 +14,12 @@ namespace opt { class TagIndexFullScanRule final : public IndexFullScanBaseRule { public: - const Pattern &pattern() const override; + const Pattern& pattern() const override; std::string toString() const override; private: TagIndexFullScanRule(); + graph::IndexScan* scan(OptContext* ctx, const graph::PlanNode* node) const override; static std::unique_ptr kInstance; }; diff --git a/tests/tck/features/lookup/LookupEdge.feature b/tests/tck/features/lookup/LookupEdge.feature index cdd2a8004..2c943e4a7 100644 --- a/tests/tck/features/lookup/LookupEdge.feature +++ b/tests/tck/features/lookup/LookupEdge.feature @@ -34,9 +34,14 @@ Feature: Test lookup on edge index Then a SemanticError should be raised at runtime: Expression (col1==201) not supported yet When executing query: """ - LOOKUP ON lookup_edge_1 WHERE lookup_edge_1.col1 == 201 OR lookup_edge_1.col5 == 20 + LOOKUP ON lookup_edge_1 WHERE lookup_edge_1.col1 == 201 OR lookup_edge_1.col5 == 201 """ Then a SemanticError should be raised at runtime: Invalid column: col5 + When executing query: + """ + LOOKUP ON lookup_edge_1 WHERE lookup_edge_1.col1 == 201 OR lookup_edge_1.col2 == 201 AND lookup_edge_1.col3 == 202 + """ + Then a SemanticError should be raised at runtime: Not supported filter When executing query: """ LOOKUP ON lookup_edge_1 WHERE lookup_edge_1.col1 == 300 @@ -91,6 +96,7 @@ Feature: Test lookup on edge index | lookup_edge_1.col1 >= 201 AND lookup_edge_1.col2 >= 201 AND lookup_edge_1.col3 == 201 | | lookup_edge_1.col1 >= 201 AND lookup_edge_1.col2 != 200 AND lookup_edge_1.col3 == 201 | | lookup_edge_1.col1 != 200 AND lookup_edge_1.col2 != 200 AND lookup_edge_1.col3 == 201 | + | lookup_edge_1.col1 == 201 OR lookup_edge_1.col2 == 201 | # TODO(yee): Test bool expression # TODO(yee): Test or expression diff --git a/tests/tck/features/lookup/LookupTag.feature b/tests/tck/features/lookup/LookupTag.feature index 1242490e9..3c714a43f 100644 --- a/tests/tck/features/lookup/LookupTag.feature +++ b/tests/tck/features/lookup/LookupTag.feature @@ -38,6 +38,11 @@ Feature: Test lookup on tag index LOOKUP ON lookup_tag_1 WHERE lookup_tag_1.col1 == 200 OR lookup_tag_1.col5 == 20; """ Then a SemanticError should be raised at runtime: Invalid column: col5 + When executing query: + """ + LOOKUP ON lookup_tag_1 WHERE lookup_tag_1.col1 == 201 OR lookup_tag_1.col2 == 201 AND lookup_tag_1.col3 == 202 + """ + Then a SemanticError should be raised at runtime: Not supported filter When executing query: """ LOOKUP ON lookup_tag_1 WHERE lookup_tag_1.col1 == 300 @@ -90,6 +95,7 @@ Feature: Test lookup on tag index | lookup_tag_1.col1 != 202 AND lookup_tag_1.col2 == 201 AND lookup_tag_1.col3 == 201 | | lookup_tag_1.col1 != 202 AND lookup_tag_1.col2 == 201 AND lookup_tag_1.col3 >= 201 | | lookup_tag_1.col1 != 202 AND lookup_tag_1.col2 >= 201 AND lookup_tag_1.col3 >= 201 | + | lookup_tag_1.col1 == 201 OR lookup_tag_1.col2 == 201 | Scenario Outline: [tag] scan without hints When executing query: