Skip to content

Commit

Permalink
rewrite param in path
Browse files Browse the repository at this point in the history
  • Loading branch information
nevermore3 committed Apr 14, 2023
1 parent e8e6c18 commit 105b520
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 4 deletions.
21 changes: 17 additions & 4 deletions src/graph/validator/FindPathValidator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,28 @@ Status FindPathValidator::validateWhere(WhereClause* where) {
return Status::OK();
}
// Not Support $-、$var、$$.tag.prop、$^.tag.prop、agg
auto expr = where->filter();
if (ExpressionUtils::findAny(expr,
auto filterExpr = where->filter();
if (ExpressionUtils::findAny(filterExpr,
{Expression::Kind::kSrcProperty,
Expression::Kind::kDstProperty,
Expression::Kind::kVarProperty,
Expression::Kind::kInputProperty})) {
return Status::SemanticError("Not support `%s' in where sentence.", expr->toString().c_str());
return Status::SemanticError("Not support `%s' in where sentence.",
filterExpr->toString().c_str());
}
where->setFilter(ExpressionUtils::rewriteLabelAttr2EdgeProp(expr));

auto undefinedParams = graph::ExpressionUtils::ExtractInnerVars(filterExpr, 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(filterExpr, qctx_);

where->setFilter(ExpressionUtils::rewriteLabelAttr2EdgeProp(newFilter));
auto filter = where->filter();

auto typeStatus = deduceExprType(filter);
Expand Down
24 changes: 24 additions & 0 deletions tests/tck/features/yield/parameter.feature
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,16 @@ Feature: Parameter
GET SUBGRAPH FROM 'Tim Duncan' WHERE like.likeness < $unknown_distance YIELD edges as e
"""
Then a SemanticError should be raised at runtime: Undefined parameters: unknown_distance
When executing query:
"""
FIND ALL PATH FROM 'Tim Duncan' TO 'Tony Parker' OVER like WHERE like.likeness > $unknown_distance YIELD path as p
"""
Then a SemanticError should be raised at runtime: Undefined parameters: unknown_distance
When executing query:
"""
FIND SHORTEST PATH FROM 'Tim Duncan' TO 'Tony Parker' OVER like WHERE like.likeness > $unknown_distance YIELD path as p
"""
Then a SemanticError should be raised at runtime: Undefined parameters: unknown_distance
When executing query:
"""
MATCH (v:player) RETURN v LIMIT $p6
Expand Down Expand Up @@ -358,6 +368,20 @@ Feature: Parameter
| e |
| [[:like "Tim Duncan"->"Manu Ginobili" @0 {likeness: 95}], [:like "Tim Duncan"->"Tony Parker" @0 {likeness: 95}], [:like "Dejounte Murray"->"Tim Duncan" @0 {likeness: 99}], [:like "Tony Parker"->"Tim Duncan" @0 {likeness: 95}]] |
| [[:like "Tony Parker"->"Manu Ginobili" @0 {likeness: 95}], [:like "Dejounte Murray"->"Manu Ginobili" @0 {likeness: 99}], [:like "Dejounte Murray"->"Tony Parker" @0 {likeness: 99}]] |
When executing query:
"""
FIND ALL PATH FROM 'Tim Duncan' TO 'Tony Parker' OVER like WHERE like.likeness > $p10-1 YIELD path AS p
"""
Then the result should be, in any order, with relax comparison:
| p |
| <("Tim Duncan")-[:like@0 {likeness: 95}]->("Tony Parker")> |
| <("Tim Duncan")-[:like@0 {likeness: 95}]->("Manu Ginobili")-[:like@0 {likeness: 90}]->("Tim Duncan")-[:like@0 {likeness: 95}]->("Tony Parker")> |
When executing query:
"""
FIND ALL PATH FROM 'Tim Duncan' TO 'Tony Parker' OVER like WHERE like.likeness > $p5[10] YIELD path AS p
"""
Then the result should be, in any order:
| p |
Scenario: [param-test-013] DML
Given an empty graph
Expand Down

0 comments on commit 105b520

Please sign in to comment.