Skip to content

Commit

Permalink
Fix error message
Browse files Browse the repository at this point in the history
  • Loading branch information
czpmango committed Mar 17, 2023
1 parent 1764ec4 commit fee1898
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 7 deletions.
3 changes: 2 additions & 1 deletion src/graph/util/ExpressionUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -275,10 +275,11 @@ std::vector<std::string> ExpressionUtils::ExtractInnerVars(const Expression *exp
if (finder(expr)) {
return {static_cast<const VariableExpression *>(expr)->var()};
}
FindVisitor visitor(finder);
FindVisitor visitor(finder, true);
const_cast<Expression *>(expr)->accept(&visitor);
auto varExprs = visitor.results();
std::vector<std::string> vars;
vars.reserve(varExprs.size());
for (const auto *varExpr : varExprs) {
vars.emplace_back(static_cast<const VariableExpression *>(varExpr)->var());
}
Expand Down
11 changes: 10 additions & 1 deletion src/graph/validator/LookupValidator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -193,11 +193,20 @@ Status LookupValidator::validateWhere() {
auto* filter = whereClause->filter();
if (filter != nullptr) {
auto vars = graph::ExpressionUtils::ExtractInnerVars(filter, qctx_);
std::vector<std::string> undefinedParams;
for (const auto& var : vars) {
if (!vctx_->existVar(var)) {
return Status::SemanticError("Undefined parameter: " + var);
undefinedParams.emplace_back(var);
}
}
if (!undefinedParams.empty()) {
return Status::SemanticError(
"Undefined parameters: " +
std::accumulate(++undefinedParams.begin(),
undefinedParams.end(),
*undefinedParams.begin(),
[](auto& lhs, auto& rhs) { return lhs + ", " + rhs; }));
}
filter = graph::ExpressionUtils::rewriteParameter(filter, qctx_);
}
if (FTIndexUtils::needTextSearch(filter)) {
Expand Down
12 changes: 9 additions & 3 deletions src/graph/validator/MatchValidator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -334,10 +334,16 @@ Status MatchValidator::buildEdgeInfo(const MatchPath *path,
// Rewrite expression to fit semantic, check type and check used aliases.
Status MatchValidator::validateFilter(const Expression *filter,
WhereClauseContext &whereClauseCtx) {
auto vars = graph::ExpressionUtils::ExtractInnerVars(filter, qctx_);
if (!vars.empty()) {
return Status::SemanticError("Undefined parameter: " + vars[0]);
auto undefinedParams = graph::ExpressionUtils::ExtractInnerVars(filter, qctx_);
if (!undefinedParams.empty()) {
return Status::SemanticError(
"Undefined parameters: " +
std::accumulate(++undefinedParams.begin(),
undefinedParams.end(),
*undefinedParams.begin(),
[](auto &lhs, auto &rhs) { return lhs + ", " + rhs; }));
}

auto *newFilter = graph::ExpressionUtils::rewriteParameter(filter, qctx_);
auto transformRes = ExpressionUtils::filterTransform(newFilter);
NG_RETURN_IF_ERROR(transformRes);
Expand Down
9 changes: 7 additions & 2 deletions tests/tck/features/yield/parameter.feature
Original file line number Diff line number Diff line change
Expand Up @@ -258,12 +258,17 @@ Feature: Parameter
"""
LOOKUP ON player WHERE ST_Distance(player.age, ST_Point($p1,$p7.a.b.c.d[0])) < $unknown_distance YIELD id(vertex)
"""
Then a SemanticError should be raised at runtime: Undefined parameter: unknown_distance
Then a SemanticError should be raised at runtime: Undefined parameters: unknown_distance
When executing query:
"""
LOOKUP ON player WHERE ST_Distance(player.age, ST_Point($p1,$p7.a.b.c.d[0])) < $unknown_distance+$unknown_factor YIELD id(vertex)
"""
Then a SemanticError should be raised at runtime: Undefined parameters: unknown_distance, unknown_factor
When executing query:
"""
MATCH (v:player) where v.player.age < $unknown_distance RETURN v
"""
Then a SemanticError should be raised at runtime: Undefined parameter: unknown_distance
Then a SemanticError should be raised at runtime: Undefined parameters: unknown_distance
When executing query:
"""
MATCH (v:player) RETURN v LIMIT $p6
Expand Down

0 comments on commit fee1898

Please sign in to comment.