From 28b89b66391b8c504762868b110e8ff6f8157937 Mon Sep 17 00:00:00 2001 From: "kyle.cao" Date: Thu, 4 Nov 2021 13:51:05 +0800 Subject: [PATCH 1/3] disable yield var fix tck --- src/parser/parser.yy | 17 ++++++++++++ .../bugfix/VariableExpression.feature | 26 +++++++++++++++++++ .../features/go/GroupbyLimit.IntVid.feature | 2 +- tests/tck/features/go/GroupbyLimit.feature | 2 +- 4 files changed, 45 insertions(+), 2 deletions(-) create mode 100644 tests/tck/features/bugfix/VariableExpression.feature diff --git a/src/parser/parser.yy b/src/parser/parser.yy index 7b5259a7eaf..cb0efef8ab4 100644 --- a/src/parser/parser.yy +++ b/src/parser/parser.yy @@ -1436,9 +1436,26 @@ yield_column delete $3; } | expression { + auto vars = graph::ExpressionUtils::collectAll($1, {Expression::Kind::kVar}); + if (!vars.empty()) { + for (auto* var : vars) { + if (!static_cast(var)->isInner()) { + throw nebula::GraphParser::syntax_error(@1, "Direct output of variable is prohibited"); + } + } + } $$ = new YieldColumn($1); } | expression KW_AS name_label { + auto vars = graph::ExpressionUtils::collectAll($1, {Expression::Kind::kVar}); + if (!vars.empty()) { + for (auto* var : vars) { + if (!static_cast(var)->isInner()) { + delete $3; + throw nebula::GraphParser::syntax_error(@1, "Direct output of variable is prohibited"); + } + } + } $$ = new YieldColumn($1, *$3); delete $3; } diff --git a/tests/tck/features/bugfix/VariableExpression.feature b/tests/tck/features/bugfix/VariableExpression.feature new file mode 100644 index 00000000000..d95560d681f --- /dev/null +++ b/tests/tck/features/bugfix/VariableExpression.feature @@ -0,0 +1,26 @@ +# Copyright (c) 2021 vesoft inc. All rights reserved. +# +# This source code is licensed under Apache 2.0 License, +# attached with Common Clause Condition 1.0, found in the LICENSES directory. +Feature: Variable usage + + Background: + Given a graph with space named "nba" + + Scenario: disable yield $var + When executing query: + """ + $var = yield 1;$var2 = yield 3;yield $var1 + $var2 + """ + Then a SyntaxError should be raised at runtime: Direct output of variable is prohibited near `$var1 + $var2' + When executing query: + """ + $var=go from "Tim Duncan" over like yield like._dst as dst;yield $var + """ + Then a SyntaxError should be raised at runtime: Direct output of variable is prohibited near `$var' + Then drop the used space + When executing query: + """ + $var=go from "Tim Duncan" over like yield like._dst as dst;yield $var[0][0] + """ + Then a SyntaxError should be raised at runtime: Direct output of variable is prohibited near `$var[0][0]' diff --git a/tests/tck/features/go/GroupbyLimit.IntVid.feature b/tests/tck/features/go/GroupbyLimit.IntVid.feature index 86e457460f6..384c12928a8 100644 --- a/tests/tck/features/go/GroupbyLimit.IntVid.feature +++ b/tests/tck/features/go/GroupbyLimit.IntVid.feature @@ -15,7 +15,7 @@ Feature: Groupby & limit Sentence """ GO FROM hash("Marco Belinelli") OVER serve YIELD $$.team.name AS name | GROUP BY $-.start_year YIELD COUNT($var) """ - Then a SemanticError should be raised at runtime: + Then a SyntaxError should be raised at runtime: Scenario: Syntax test4 When executing query: diff --git a/tests/tck/features/go/GroupbyLimit.feature b/tests/tck/features/go/GroupbyLimit.feature index 2a282a2b7b0..7706c27c6b2 100644 --- a/tests/tck/features/go/GroupbyLimit.feature +++ b/tests/tck/features/go/GroupbyLimit.feature @@ -22,7 +22,7 @@ Feature: Groupby & limit Sentence """ GO FROM "Marco Belinelli" OVER serve YIELD $$.team.name AS name | GROUP BY $-.start_year YIELD COUNT($var) """ - Then a SemanticError should be raised at runtime: + Then a SyntaxError should be raised at runtime: Scenario: Syntax test4 When executing query: From 4d20ec80a0bee9eafafd5912959e7f206ea63432 Mon Sep 17 00:00:00 2001 From: "kyle.cao" Date: Tue, 23 Nov 2021 17:33:07 +0800 Subject: [PATCH 2/3] small fix --- src/graph/optimizer/rule/TopNRule.cpp | 1 + src/graph/util/ExpressionUtils.cpp | 10 ++++++++++ src/graph/util/ExpressionUtils.h | 2 ++ src/parser/parser.yy | 21 ++++++--------------- 4 files changed, 19 insertions(+), 15 deletions(-) diff --git a/src/graph/optimizer/rule/TopNRule.cpp b/src/graph/optimizer/rule/TopNRule.cpp index 194ec2788bd..17171fc4872 100644 --- a/src/graph/optimizer/rule/TopNRule.cpp +++ b/src/graph/optimizer/rule/TopNRule.cpp @@ -4,6 +4,7 @@ */ #include "graph/optimizer/rule/TopNRule.h" + #include "graph/optimizer/OptContext.h" #include "graph/optimizer/OptGroup.h" #include "graph/planner/plan/PlanNode.h" diff --git a/src/graph/util/ExpressionUtils.cpp b/src/graph/util/ExpressionUtils.cpp index aff0c9f14ce..ee3c7913ad0 100644 --- a/src/graph/util/ExpressionUtils.cpp +++ b/src/graph/util/ExpressionUtils.cpp @@ -63,6 +63,16 @@ std::vector ExpressionUtils::collectAll( return std::move(visitor).results(); } +bool ExpressionUtils::checkVarExprIfExist(const Expression *expr) { + auto vars = ExpressionUtils::collectAll(expr, {Expression::Kind::kVar}); + for (auto *var : vars) { + if (!static_cast(var)->isInner()) { + return true; + } + } + return false; +} + std::vector ExpressionUtils::findAllStorage(const Expression *expr) { return collectAll(expr, {Expression::Kind::kTagProperty, diff --git a/src/graph/util/ExpressionUtils.h b/src/graph/util/ExpressionUtils.h index 484f2db4127..c6d1fa5b87b 100644 --- a/src/graph/util/ExpressionUtils.h +++ b/src/graph/util/ExpressionUtils.h @@ -44,6 +44,8 @@ class ExpressionUtils { static std::vector collectAll( const Expression* self, const std::unordered_set& expected); + static bool checkVarExprIfExist(const Expression* expr); + static std::vector findAllStorage(const Expression* expr); static std::vector findAllInputVariableProp(const Expression* expr); diff --git a/src/parser/parser.yy b/src/parser/parser.yy index f0f673bff7a..891de6951cf 100644 --- a/src/parser/parser.yy +++ b/src/parser/parser.yy @@ -1448,25 +1448,16 @@ yield_column delete $3; } | expression { - auto vars = graph::ExpressionUtils::collectAll($1, {Expression::Kind::kVar}); - if (!vars.empty()) { - for (auto* var : vars) { - if (!static_cast(var)->isInner()) { - throw nebula::GraphParser::syntax_error(@1, "Direct output of variable is prohibited"); - } - } + if (graph::ExpressionUtils::checkVarExprIfExist($1)) { + delete $3; + throw nebula::GraphParser::syntax_error(@1, "Direct output of variable is prohibited"); } $$ = new YieldColumn($1); } | expression KW_AS name_label { - auto vars = graph::ExpressionUtils::collectAll($1, {Expression::Kind::kVar}); - if (!vars.empty()) { - for (auto* var : vars) { - if (!static_cast(var)->isInner()) { - delete $3; - throw nebula::GraphParser::syntax_error(@1, "Direct output of variable is prohibited"); - } - } + if (graph::ExpressionUtils::checkVarExprIfExist($1)) { + delete $3; + throw nebula::GraphParser::syntax_error(@1, "Direct output of variable is prohibited"); } $$ = new YieldColumn($1, *$3); delete $3; From 3ade797121459a600c281764077918ee5db12a75 Mon Sep 17 00:00:00 2001 From: "kyle.cao" Date: Tue, 23 Nov 2021 17:35:28 +0800 Subject: [PATCH 3/3] small fix --- src/parser/parser.yy | 1 - 1 file changed, 1 deletion(-) diff --git a/src/parser/parser.yy b/src/parser/parser.yy index 891de6951cf..00c2278c9b4 100644 --- a/src/parser/parser.yy +++ b/src/parser/parser.yy @@ -1449,7 +1449,6 @@ yield_column } | expression { if (graph::ExpressionUtils::checkVarExprIfExist($1)) { - delete $3; throw nebula::GraphParser::syntax_error(@1, "Direct output of variable is prohibited"); } $$ = new YieldColumn($1);