From 9b05e980d7bbc6afcfcdcff7683a91942b4f707c Mon Sep 17 00:00:00 2001 From: "kyle.cao" Date: Wed, 8 Dec 2021 16:14:13 +0800 Subject: [PATCH] fix inconsistent variable in yield and from clause --- src/graph/validator/GoValidator.cpp | 20 +++++++++++++++++--- tests/tck/features/go/GO.feature | 28 ++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+), 3 deletions(-) diff --git a/src/graph/validator/GoValidator.cpp b/src/graph/validator/GoValidator.cpp index 1866f66e9a8..03da2cede0d 100644 --- a/src/graph/validator/GoValidator.cpp +++ b/src/graph/validator/GoValidator.cpp @@ -36,9 +36,23 @@ Status GoValidator::validateImpl() { return Status::SemanticError("$- must be referred in FROM before used in WHERE or YIELD"); } - if (!exprProps.varProps().empty() && goCtx_->from.fromType != kVariable) { - return Status::SemanticError( - "A variable must be referred in FROM before used in WHERE or YIELD"); + if (!exprProps.varProps().empty()) { + if (goCtx_->from.fromType != kVariable) { + return Status::SemanticError( + "A variable must be referred in FROM before used in WHERE or YIELD"); + } + auto varPropsMap = exprProps.varProps(); + std::vector keys; + for (const auto& [k, v] : varPropsMap) { + keys.emplace_back(k); + } + if (keys.size() > 1) { + return Status::SemanticError("Multiple variable property is not supported in WHERE or YIELD"); + } + if (keys.front() != goCtx_->from.userDefinedVarName) { + return Status::SemanticError( + "A variable must be referred in FROM before used in WHERE or YIELD"); + } } if ((!exprProps.inputProps().empty() && !exprProps.varProps().empty()) || diff --git a/tests/tck/features/go/GO.feature b/tests/tck/features/go/GO.feature index 3ed44e7a4a2..9ee57c3eb26 100644 --- a/tests/tck/features/go/GO.feature +++ b/tests/tck/features/go/GO.feature @@ -753,6 +753,34 @@ Feature: Go Sentence RETURN $B IF $A IS NOT NULL """ Then a SemanticError should be raised at runtime: `$a.id', not exist variable `a' + When executing query: + """ + $A = GO FROM 'Tim Duncan' OVER like YIELD like._dst AS dst; + $B = GO FROM $A.dst OVER like YIELD like._dst AS dst; + GO FROM $A.dst over like YIELD like._dst AS dst, $B.dst + """ + Then a SemanticError should be raised at runtime: A variable must be referred in FROM before used in WHERE or YIELD + When executing query: + """ + $A = GO FROM 'Tim Duncan' OVER like YIELD like._dst AS dst; + $B = GO FROM $A.dst OVER like YIELD like._dst AS dst; + GO FROM $A.dst over like WHERE $B.dst > "A" YIELD like._dst AS dst + """ + Then a SemanticError should be raised at runtime: A variable must be referred in FROM before used in WHERE or YIELD + When executing query: + """ + $A = GO FROM 'Tim Duncan' OVER like YIELD like._dst AS dst; + $B = GO FROM $A.dst OVER like YIELD like._dst AS dst; + GO FROM $A.dst over like YIELD like._dst AS dst, $B.dst, $A.dst + """ + Then a SemanticError should be raised at runtime: Multiple variable property is not supported in WHERE or YIELD + When executing query: + """ + $A = GO FROM 'Tim Duncan' OVER like YIELD like._dst AS dst; + $B = GO FROM $A.dst OVER like YIELD like._dst AS dst; + GO FROM $A.dst over like WHERE $A.dst > "A" and $B.dst > "B" YIELD like._dst + """ + Then a SemanticError should be raised at runtime: Multiple variable property is not supported in WHERE or YIELD When executing query: """ RETURN $rA IF $rA IS NOT NULL;