Skip to content

Commit

Permalink
fix inconsistent variable in yield and from clause
Browse files Browse the repository at this point in the history
  • Loading branch information
czpmango committed Dec 8, 2021
1 parent d38fc07 commit f140d09
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
20 changes: 17 additions & 3 deletions src/graph/validator/GoValidator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::string> 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()) ||
Expand Down
7 changes: 7 additions & 0 deletions tests/tck/features/go/GO.feature
Original file line number Diff line number Diff line change
Expand Up @@ -753,6 +753,13 @@ 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:
"""
RETURN $rA IF $rA IS NOT NULL;
Expand Down

0 comments on commit f140d09

Please sign in to comment.