diff --git a/src/common/expression/PropertyExpression.h b/src/common/expression/PropertyExpression.h index 26cf1cee943..a9baf8d47a7 100644 --- a/src/common/expression/PropertyExpression.h +++ b/src/common/expression/PropertyExpression.h @@ -155,6 +155,10 @@ class LabelTagPropertyExpression final : public PropertyExpression { return label_; } + void setLabel(Expression* label) { + label_ = label; + } + private: LabelTagPropertyExpression(ObjectPool* pool, Expression* label = nullptr, diff --git a/src/graph/visitor/RewriteVisitor.cpp b/src/graph/visitor/RewriteVisitor.cpp index 3da631f210b..da207c2dbee 100644 --- a/src/graph/visitor/RewriteVisitor.cpp +++ b/src/graph/visitor/RewriteVisitor.cpp @@ -237,6 +237,18 @@ void RewriteVisitor::visit(PathBuildExpression *expr) { } } +void RewriteVisitor::visit(LabelTagPropertyExpression *expr) { + if (!care(expr->kind())) { + return; + } + auto label = expr->label(); + if (matcher_(label)) { + expr->setLabel(rewriter_(label)); + } else { + label->accept(this); + } +} + void RewriteVisitor::visit(AttributeExpression *expr) { if (!care(expr->kind())) { return; diff --git a/src/graph/visitor/RewriteVisitor.h b/src/graph/visitor/RewriteVisitor.h index 365908ed288..85d30836495 100644 --- a/src/graph/visitor/RewriteVisitor.h +++ b/src/graph/visitor/RewriteVisitor.h @@ -67,12 +67,12 @@ class RewriteVisitor final : public ExprVisitorImpl { void visit(RelationalExpression*) override; void visit(SubscriptExpression*) override; void visit(PathBuildExpression*) override; + void visit(LabelTagPropertyExpression*) override; void visit(SubscriptRangeExpression*) override; void visit(ConstantExpression*) override {} void visit(LabelExpression*) override {} void visit(UUIDExpression*) override {} void visit(LabelAttributeExpression*) override {} - void visit(LabelTagPropertyExpression*) override {} void visit(VariableExpression*) override {} void visit(VersionedVariableExpression*) override {} void visit(TagPropertyExpression*) override {} diff --git a/tests/tck/features/match/With.feature b/tests/tck/features/match/With.feature index eefe0b9a0c4..dd8fa2f115b 100644 --- a/tests/tck/features/match/With.feature +++ b/tests/tck/features/match/With.feature @@ -1,3 +1,4 @@ +@jmq Feature: With clause Background: @@ -217,6 +218,23 @@ Feature: With clause Then the result should be, in any order, with relax comparison: | avg | max | | 90.0 | 90 | + When executing query: + """ + MATCH (:player {name:"Tim Duncan"})-[e:like]->(dst) + WITH dst AS b + RETURN b.player.age AS age, b + """ + Then the result should be, in any order, with relax comparison: + | age | b | + | 36 | ("Tony Parker" :player{age: 36, name: "Tony Parker"}) | + | 41 | ("Manu Ginobili" :player{age: 41, name: "Manu Ginobili"}) | + When executing query: + """ + MATCH (:player {name:"Tim Duncan"})-[e:like]->(dst) + WITH dst AS b + RETURN b.age AS age, b + """ + Then a SemanticError should be raised at runtime: To get the property of the vertex in `b.age', should use the format `var.tag.prop' @skip Scenario: with match return diff --git a/tests/tck/features/optimizer/CollapseProjectRule.feature b/tests/tck/features/optimizer/CollapseProjectRule.feature index ea6f339a162..12d2144c46b 100644 --- a/tests/tck/features/optimizer/CollapseProjectRule.feature +++ b/tests/tck/features/optimizer/CollapseProjectRule.feature @@ -1,6 +1,7 @@ # Copyright (c) 2021 vesoft inc. All rights reserved. # # This source code is licensed under Apache 2.0 License. +@jmq Feature: Collapse Project Rule Background: @@ -47,3 +48,20 @@ Feature: Collapse Project Rule | 6 | Project | 5 | | | 5 | TagIndexPrefixScan | 0 | | | 0 | Start | | | + When profiling query: + """ + MATCH (:player {name:"Tim Duncan"})-[e:like]->(dst) + WITH dst AS b + RETURN b.player.age AS age + """ + Then the result should be, in any order: + | age | + | 36 | + | 41 | + And the execution plan should be: + | id | name | dependencies | operator info | + | 11 | Project | 4 | | + | 4 | AppendVertices | 3 | | + | 3 | Traverse | 8 | | + | 8 | IndexScan | 2 | {"indexCtx": {"columnHints":{"scanType":"PREFIX","column":"name","beginValue":"\"Tim Duncan\"","endValue":"__EMPTY__","includeBegin":"true","includeEnd":"false"}}} | + | 2 | Start | | |