Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cherry pick 3.3 (1017-1020) #4761

Merged
merged 8 commits into from
Oct 20, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fixed case-when error (#4744)
* 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 committed Oct 20, 2022
commit 88ceadd166a655e9f1c167cbb560d4c78f16ff60
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 |