From 9f38d495a8c6764e82609b57df05cf0a5dc70b3f Mon Sep 17 00:00:00 2001 From: canon <87342612+caton-hpg@users.noreply.github.com> Date: Thu, 20 Oct 2022 13:52:25 +0800 Subject: [PATCH] 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> --- src/graph/visitor/PropertyTrackerVisitor.cpp | 34 +++- tests/tck/features/expression/Case.feature | 176 +++++++++++++++++++ 2 files changed, 207 insertions(+), 3 deletions(-) diff --git a/src/graph/visitor/PropertyTrackerVisitor.cpp b/src/graph/visitor/PropertyTrackerVisitor.cpp index 5ec7e8629f5..ce3042c717a 100644 --- a/src/graph/visitor/PropertyTrackerVisitor.cpp +++ b/src/graph/visitor/PropertyTrackerVisitor.cpp @@ -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(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(lhs); auto *subLeftExpr = subscriptExpr->left(); @@ -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(lhs); auto funName = funCallExpr->name(); std::transform(funName.begin(), funName.end(), funName.begin(), ::tolower); @@ -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(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(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(argExpr); auto *subLeftExpr = subscriptExpr->left(); auto leftKind = subLeftExpr->kind(); diff --git a/tests/tck/features/expression/Case.feature b/tests/tck/features/expression/Case.feature index 65441a49509..f4dad8a1b9c 100644 --- a/tests/tck/features/expression/Case.feature +++ b/tests/tck/features/expression/Case.feature @@ -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 |