From 9fcbe5b48b21e4415d248aa42714a93f80bc0d42 Mon Sep 17 00:00:00 2001 From: "kyle.cao" Date: Tue, 14 Feb 2023 09:15:55 +0800 Subject: [PATCH] Fix the crash when lookup parameter expression eval in storage #5336 --- src/graph/validator/LookupValidator.cpp | 3 + src/storage/ExprVisitorBase.cpp | 4 +- tests/tck/features/yield/parameter.feature | 79 +++++++++++++++++++++- 3 files changed, 82 insertions(+), 4 deletions(-) diff --git a/src/graph/validator/LookupValidator.cpp b/src/graph/validator/LookupValidator.cpp index 4f185327280..31bbe16f4cc 100644 --- a/src/graph/validator/LookupValidator.cpp +++ b/src/graph/validator/LookupValidator.cpp @@ -191,6 +191,9 @@ Status LookupValidator::validateWhere() { } auto* filter = whereClause->filter(); + if (filter != nullptr) { + filter = graph::ExpressionUtils::rewriteParameter(filter, qctx_); + } if (FTIndexUtils::needTextSearch(filter)) { lookupCtx_->isFulltextIndex = true; lookupCtx_->fulltextExpr = filter; diff --git a/src/storage/ExprVisitorBase.cpp b/src/storage/ExprVisitorBase.cpp index 8d8b21ec603..d2f286b1fa2 100644 --- a/src/storage/ExprVisitorBase.cpp +++ b/src/storage/ExprVisitorBase.cpp @@ -33,9 +33,7 @@ void ExprVisitorBase::visit(SubscriptExpression *expr) { expr->left()->accept(this); expr->right()->accept(this); } -void ExprVisitorBase::visit(AttributeExpression *expr) { - fatal(expr); -} +void ExprVisitorBase::visit(AttributeExpression *) {} void ExprVisitorBase::visit(LogicalExpression *expr) { for (auto operand : expr->operands()) { operand->accept(this); diff --git a/tests/tck/features/yield/parameter.feature b/tests/tck/features/yield/parameter.feature index 83f44a85fa8..28373b4971c 100644 --- a/tests/tck/features/yield/parameter.feature +++ b/tests/tck/features/yield/parameter.feature @@ -253,7 +253,7 @@ Feature: Parameter """ LOOKUP ON player WHERE player.age>$p2+43 """ - Then a SemanticError should be raised at runtime: Column type error : age + Then a SemanticError should be raised at runtime: Type error `(true+43)' When executing query: """ MATCH (v:player) RETURN v LIMIT $p6 @@ -330,3 +330,80 @@ Feature: Parameter | v | | BAD_TYPE | | BAD_TYPE | +<<<<<<< HEAD +======= + + Scenario: [param-test-013] DML + Given an empty graph + And load "nba" csv data to a new space + When executing query: + """ + insert vertex player(name, age) values "1":($p6.c, $p1+40) + """ + Then the execution should be successful + When executing query: + """ + insert vertex player(age, name) values "1":($p6.c, $p1+40) + """ + Then a ExecutionError should be raised at runtime: Storage Error: The data type does not meet the requirements. Use the correct type of data. + When executing query: + """ + insert edge like(likeness) values "1"->"2":($p1+40) + """ + Then the execution should be successful + When executing query: + """ + insert edge like(likeness) values "1"->"2":($p6.c) + """ + Then a ExecutionError should be raised at runtime: Storage Error: The data type does not meet the requirements. Use the correct type of data. + When executing query: + """ + update vertex on player "1" set age=age+$p1 when age>$p1 + """ + Then the execution should be successful + When executing query: + """ + update vertex on player "1" set age=age+$p6.c when age>$p1 + """ + Then a ExecutionError should be raised at runtime: Storage Error: Invalid data, may be wrong value type. + When executing query: + """ + update edge on like "1"->"2" set likeness=likeness+$p1 + """ + Then the execution should be successful + When executing query: + """ + update edge on like "1"->"2" set likeness=likeness+$p6.c when likeness>300 + """ + Then the execution should be successful + When executing query: + """ + update edge on like "1"->"2" set likeness=likeness+$p6.c when likeness<300 + """ + Then a ExecutionError should be raised at runtime: Storage Error: Invalid data, may be wrong value type. + When executing query: + """ + update edge on like "1"->"2" set likeness=likeness+$p6.c when likeness>$p1 + """ + Then a ExecutionError should be raised at runtime: Storage Error: Invalid data, may be wrong value type. + When executing query: + """ + update edge on like "1"->"2" set likeness=likeness+$p6.a when likeness>$p1 + """ + Then the execution should be successful + When executing query: + """ + $var=lookup on player where player.name==$p6.c and player.age in [43,35,42,45] yield id(vertex) AS VertexID;DELETE VERTEX $var.VertexID;RETURN count($var.VertexID) AS record + """ + Then the execution should be successful + When executing query: + """ + $var=lookup on player where player.name==$p3 and player.age in [43,35,42,45] yield id(vertex) AS VertexID;DELETE VERTEX $var.VertexID;RETURN count($var.VertexID) AS record + """ + Then the execution should be successful + When executing query: + """ + $var=lookup on player where player.name==$p7.a.b.d[4] and player.age in [43,35,42,45] yield id(vertex) AS VertexID;DELETE VERTEX $var.VertexID;RETURN count($var.VertexID) AS record + """ + Then the execution should be successful +>>>>>>> c20467f19 (Fix the crash when lookup parameter expression eval in storage (#5336))