Skip to content
This repository has been archived by the owner on Dec 1, 2022. It is now read-only.

fix alias check in with clause #1258

Merged
merged 3 commits into from
Jul 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/validator/MatchValidator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,15 @@ Status MatchValidator::validateWith(const WithClause *with,
std::vector<const Expression *> exprs;
exprs.reserve(with->columns()->size());
for (auto *col : with->columns()->columns()) {
auto labelExprs = ExpressionUtils::collectAll(col->expr(), {Expression::Kind::kLabel});
for (auto *labelExpr : labelExprs) {
DCHECK_EQ(labelExpr->kind(), Expression::Kind::kLabel);
auto label = static_cast<const LabelExpression *>(labelExpr)->name();
if (!withClauseCtx.yield->aliasesUsed ||
!withClauseCtx.yield->aliasesUsed->count(label)) {
return Status::SemanticError("Variable `%s` not defined", label.c_str());
}
}
if (col->alias().empty()) {
if (col->expr()->kind() == Expression::Kind::kLabel) {
col->setAlias(col->toString());
Expand Down
23 changes: 16 additions & 7 deletions tests/tck/features/match/With.feature
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,6 @@ Feature: With clause
Then the result should be, in any order, with relax comparison:
| a | b |
| [1,2,3] | "hello" |
When executing query:
"""
WITH [1, 2, 3] AS a
WITH a, "hello"
RETURN a
"""
Then a SemanticError should be raised at runtime: Expression in WITH must be aliased (use AS)

Scenario: with agg return
When executing query:
Expand Down Expand Up @@ -199,3 +192,19 @@ Feature: With clause
Then the result should be, in any order, with relax comparison:
| exists(m.abc) | exists(NULL.abc) |
| NULL | NULL |

Scenario: error check
When executing query:
"""
WITH [1, 2, 3] AS a
WITH a, "hello"
RETURN a
"""
Then a SemanticError should be raised at runtime: Expression in WITH must be aliased (use AS)
When executing query:
"""
WITH [1, 2, 3] AS a
WITH a, a+b AS c
RETURN a
"""
Then a SemanticError should be raised at runtime: Variable `b` not defined