Skip to content

Commit

Permalink
fix collapseProjectRule
Browse files Browse the repository at this point in the history
  • Loading branch information
nevermore3 committed Jan 17, 2022
1 parent 5865318 commit ddd3e4b
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/common/expression/PropertyExpression.h
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,10 @@ class LabelTagPropertyExpression final : public PropertyExpression {
return label_;
}

void setLabel(Expression* label) {
label_ = label;
}

private:
LabelTagPropertyExpression(ObjectPool* pool,
Expression* label = nullptr,
Expand Down
12 changes: 12 additions & 0 deletions src/graph/visitor/RewriteVisitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/graph/visitor/RewriteVisitor.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {}
Expand Down
18 changes: 18 additions & 0 deletions tests/tck/features/match/With.feature
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
@jmq
Feature: With clause

Background:
Expand Down Expand Up @@ -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
Expand Down
18 changes: 18 additions & 0 deletions tests/tck/features/optimizer/CollapseProjectRule.feature
Original file line number Diff line number Diff line change
@@ -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:
Expand Down Expand Up @@ -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 | | |

0 comments on commit ddd3e4b

Please sign in to comment.