Skip to content

Commit

Permalink
fixed case-when error (#4744)
Browse files Browse the repository at this point in the history
* fixed case-when error

* fix tck

* fix tck

* fix tck

Co-authored-by: Sophie <84560950+Sophie-Xie@users.noreply.github.com>
  • Loading branch information
caton-hpg and Sophie-Xie authored Oct 20, 2022
1 parent 0447e78 commit 9f38d49
Show file tree
Hide file tree
Showing 2 changed files with 207 additions and 3 deletions.
34 changes: 31 additions & 3 deletions src/graph/visitor/PropertyTrackerVisitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,20 @@ void PropertyTrackerVisitor::visit(AttributeExpression *expr) {
propsUsed_.insertEdgeProp(edgeAlias, unKnowType_, propName);
break;
}
case Expression::Kind::kCase: { // (case xxx).name
auto *casePropExpr = static_cast<CaseExpression *>(lhs);
if (casePropExpr->hasCondition()) {
casePropExpr->condition()->accept(this);
}
if (casePropExpr->hasDefault()) {
casePropExpr->defaultResult()->accept(this);
}
for (const auto &whenThen : casePropExpr->cases()) {
whenThen.when->accept(this);
whenThen.then->accept(this);
}
break;
}
case Expression::Kind::kSubscript: { // $-.e[0].name
auto *subscriptExpr = static_cast<SubscriptExpression *>(lhs);
auto *subLeftExpr = subscriptExpr->left();
Expand All @@ -199,7 +213,7 @@ void PropertyTrackerVisitor::visit(AttributeExpression *expr) {
}
break;
}
case Expression::Kind::kFunctionCall: { // properties(t3).name
case Expression::Kind::kFunctionCall: {
auto *funCallExpr = static_cast<FunctionCallExpression *>(lhs);
auto funName = funCallExpr->name();
std::transform(funName.begin(), funName.end(), funName.begin(), ::tolower);
Expand All @@ -210,14 +224,28 @@ void PropertyTrackerVisitor::visit(AttributeExpression *expr) {
auto kind = argExpr->kind();
switch (kind) {
case Expression::Kind::kVarProperty:
case Expression::Kind::kInputProperty: {
case Expression::Kind::kInputProperty: { // properties($e).name
// match (v) return properties(v).name
auto *inputPropExpr = static_cast<InputPropertyExpression *>(argExpr);
auto &aliasName = inputPropExpr->prop();
propsUsed_.insertVertexProp(aliasName, unKnowType_, propName);
break;
}
case Expression::Kind::kSubscript: {
case Expression::Kind::kCase: { // properties(case xxx).name
auto *casePropExpr = static_cast<CaseExpression *>(argExpr);
if (casePropExpr->hasCondition()) {
casePropExpr->condition()->accept(this);
}
if (casePropExpr->hasDefault()) {
casePropExpr->defaultResult()->accept(this);
}
for (const auto &whenThen : casePropExpr->cases()) {
whenThen.when->accept(this);
whenThen.then->accept(this);
}
break;
}
case Expression::Kind::kSubscript: { // properties($-.e[0]).name
auto *subscriptExpr = static_cast<SubscriptExpression *>(argExpr);
auto *subLeftExpr = subscriptExpr->left();
auto leftKind = subLeftExpr->kind();
Expand Down
176 changes: 176 additions & 0 deletions tests/tck/features/expression/Case.feature
Original file line number Diff line number Diff line change
Expand Up @@ -304,3 +304,179 @@ Feature: Case Expression
| like._dst |
| "Manu Ginobili" |
| "Tony Parker" |

Scenario: use generic case in match
When executing query:
"""
match (a:player)-[e:like]->(b) with case when e.likeness > 90 then e else {likeness:13} end as n return n.likeness;
"""
Then the result should be, in any order:
| n.likeness |
| 100 |
| 13 |
| 13 |
| 13 |
| 99 |
| 13 |
| 13 |
| 13 |
| 13 |
| 13 |
| 13 |
| 13 |
| 99 |
| 13 |
| 13 |
| 13 |
| 99 |
| 13 |
| 13 |
| 13 |
| 13 |
| 13 |
| 13 |
| 95 |
| 99 |
| 13 |
| 13 |
| 13 |
| 13 |
| 99 |
| 13 |
| 95 |
| 13 |
| 13 |
| 13 |
| 13 |
| 99 |
| 13 |
| 13 |
| 13 |
| 13 |
| 99 |
| 13 |
| 13 |
| 13 |
| 99 |
| 13 |
| 13 |
| 13 |
| 13 |
| 99 |
| 99 |
| 99 |
| 13 |
| 13 |
| 13 |
| 13 |
| 13 |
| 13 |
| 100 |
| 13 |
| 13 |
| 13 |
| 95 |
| 99 |
| 13 |
| 13 |
| 13 |
| 13 |
| 95 |
| 13 |
| 95 |
| 99 |
| 13 |
| 13 |
| 13 |
| 13 |
| 13 |
| 13 |
| 13 |
| 13 |
When executing query:
"""
match (a:player)-[e:like]->(b) with properties(case when e.likeness > 90 then e else {likeness:13} end) as n return n.likeness;
"""
Then the result should be, in any order:
| n.likeness |
| 100 |
| 13 |
| 13 |
| 13 |
| 99 |
| 13 |
| 13 |
| 13 |
| 13 |
| 13 |
| 13 |
| 13 |
| 99 |
| 13 |
| 13 |
| 13 |
| 99 |
| 13 |
| 13 |
| 13 |
| 13 |
| 13 |
| 13 |
| 95 |
| 99 |
| 13 |
| 13 |
| 13 |
| 13 |
| 99 |
| 13 |
| 95 |
| 13 |
| 13 |
| 13 |
| 13 |
| 99 |
| 13 |
| 13 |
| 13 |
| 13 |
| 99 |
| 13 |
| 13 |
| 13 |
| 99 |
| 13 |
| 13 |
| 13 |
| 13 |
| 99 |
| 99 |
| 99 |
| 13 |
| 13 |
| 13 |
| 13 |
| 13 |
| 13 |
| 100 |
| 13 |
| 13 |
| 13 |
| 95 |
| 99 |
| 13 |
| 13 |
| 13 |
| 13 |
| 95 |
| 13 |
| 95 |
| 99 |
| 13 |
| 13 |
| 13 |
| 13 |
| 13 |
| 13 |
| 13 |
| 13 |

0 comments on commit 9f38d49

Please sign in to comment.