Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit adb13b2

Browse files
rewrite param in subgraph & path (vesoft-inc#5500)
* check param in subgraph * rewrite param in path --------- Co-authored-by: Sophie <[email protected]>
1 parent 46710df commit adb13b2

File tree

3 files changed

+73
-11
lines changed

3 files changed

+73
-11
lines changed

src/graph/validator/FindPathValidator.cpp

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,28 @@ Status FindPathValidator::validateWhere(WhereClause* where) {
3737
return Status::OK();
3838
}
3939
// Not Support $-、$var、$$.tag.prop、$^.tag.prop、agg
40-
auto expr = where->filter();
41-
if (ExpressionUtils::findAny(expr,
40+
auto filterExpr = where->filter();
41+
if (ExpressionUtils::findAny(filterExpr,
4242
{Expression::Kind::kSrcProperty,
4343
Expression::Kind::kDstProperty,
4444
Expression::Kind::kVarProperty,
4545
Expression::Kind::kInputProperty})) {
46-
return Status::SemanticError("Not support `%s' in where sentence.", expr->toString().c_str());
46+
return Status::SemanticError("Not support `%s' in where sentence.",
47+
filterExpr->toString().c_str());
4748
}
48-
where->setFilter(ExpressionUtils::rewriteLabelAttr2EdgeProp(expr));
49+
50+
auto undefinedParams = graph::ExpressionUtils::ExtractInnerVars(filterExpr, qctx_);
51+
if (!undefinedParams.empty()) {
52+
return Status::SemanticError(
53+
"Undefined parameters: " +
54+
std::accumulate(++undefinedParams.begin(),
55+
undefinedParams.end(),
56+
*undefinedParams.begin(),
57+
[](auto& lhs, auto& rhs) { return lhs + ", " + rhs; }));
58+
}
59+
auto* newFilter = graph::ExpressionUtils::rewriteParameter(filterExpr, qctx_);
60+
61+
where->setFilter(ExpressionUtils::rewriteLabelAttr2EdgeProp(newFilter));
4962
auto filter = where->filter();
5063

5164
auto typeStatus = deduceExprType(filter);

src/graph/validator/GetSubgraphValidator.cpp

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -126,17 +126,29 @@ Status GetSubgraphValidator::validateWhere(WhereClause* where) {
126126
if (where == nullptr) {
127127
return Status::OK();
128128
}
129-
auto* expr = where->filter();
130-
if (ExpressionUtils::findAny(expr,
129+
auto* filterExpr = where->filter();
130+
if (ExpressionUtils::findAny(filterExpr,
131131
{Expression::Kind::kAggregate,
132132
Expression::Kind::kSrcProperty,
133133
Expression::Kind::kVarProperty,
134134
Expression::Kind::kInputProperty,
135135
Expression::Kind::kLogicalOr})) {
136-
return Status::SemanticError("Not support `%s' in where sentence.", expr->toString().c_str());
136+
return Status::SemanticError("Not support `%s' in where sentence.",
137+
filterExpr->toString().c_str());
137138
}
138139

139-
where->setFilter(ExpressionUtils::rewriteLabelAttr2EdgeProp(expr));
140+
auto undefinedParams = graph::ExpressionUtils::ExtractInnerVars(filterExpr, qctx_);
141+
if (!undefinedParams.empty()) {
142+
return Status::SemanticError(
143+
"Undefined parameters: " +
144+
std::accumulate(++undefinedParams.begin(),
145+
undefinedParams.end(),
146+
*undefinedParams.begin(),
147+
[](auto& lhs, auto& rhs) { return lhs + ", " + rhs; }));
148+
}
149+
auto* newFilter = graph::ExpressionUtils::rewriteParameter(filterExpr, qctx_);
150+
151+
where->setFilter(ExpressionUtils::rewriteLabelAttr2EdgeProp(newFilter));
140152
auto filter = where->filter();
141153
auto typeStatus = deduceExprType(filter);
142154
NG_RETURN_IF_ERROR(typeStatus);
@@ -169,11 +181,11 @@ Status GetSubgraphValidator::validateWhere(WhereClause* where) {
169181
}
170182

171183
auto condition = filter->clone();
172-
if (ExpressionUtils::findAny(expr, {Expression::Kind::kDstProperty})) {
184+
if (ExpressionUtils::findAny(filter, {Expression::Kind::kDstProperty})) {
173185
auto visitor = ExtractFilterExprVisitor::makePushGetVertices(qctx_->objPool());
174186
filter->accept(&visitor);
175187
if (!visitor.ok()) {
176-
return Status::SemanticError("Push target vertices filter error: " + expr->toString());
188+
return Status::SemanticError("Push target vertices filter error: " + filter->toString());
177189
}
178190
subgraphCtx_->edgeFilter = visitor.remainedExpr();
179191
auto tagFilter = visitor.extractedExpr() ? visitor.extractedExpr() : filter;

tests/tck/features/yield/parameter.feature

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Feature: Parameter
66
Background:
77
Given an empty graph
88
And load "nba" csv data to a new space
9-
Given parameters: {"p1":1,"p2":true,"p3":"Tim Duncan","p4":3.3,"p5":[1,true,3],"p6":{"a":3,"b":false,"c":"Tim Duncan"},"p7":{"a":{"b":{"c":"Tim Duncan","d":[1,2,3,true,"Tim Duncan"]}}},"p8":"Manu Ginobili", "p9":["Tim Duncan","Tony Parker"]}
9+
Given parameters: {"p1":1,"p2":true,"p3":"Tim Duncan","p4":3.3,"p5":[1,true,3],"p6":{"a":3,"b":false,"c":"Tim Duncan"},"p7":{"a":{"b":{"c":"Tim Duncan","d":[1,2,3,true,"Tim Duncan"]}}},"p8":"Manu Ginobili", "p9":["Tim Duncan","Tony Parker"], "p10":90}
1010

1111
Scenario: [param-test-001] without define param
1212
When executing query:
@@ -269,6 +269,21 @@ Feature: Parameter
269269
MATCH (v:player) where v.player.age < $unknown_distance RETURN v
270270
"""
271271
Then a SemanticError should be raised at runtime: Undefined parameters: unknown_distance
272+
When executing query:
273+
"""
274+
GET SUBGRAPH FROM 'Tim Duncan' WHERE like.likeness < $unknown_distance YIELD edges as e
275+
"""
276+
Then a SemanticError should be raised at runtime: Undefined parameters: unknown_distance
277+
When executing query:
278+
"""
279+
FIND ALL PATH FROM 'Tim Duncan' TO 'Tony Parker' OVER like WHERE like.likeness > $unknown_distance YIELD path as p
280+
"""
281+
Then a SemanticError should be raised at runtime: Undefined parameters: unknown_distance
282+
When executing query:
283+
"""
284+
FIND SHORTEST PATH FROM 'Tim Duncan' TO 'Tony Parker' OVER like WHERE like.likeness > $unknown_distance YIELD path as p
285+
"""
286+
Then a SemanticError should be raised at runtime: Undefined parameters: unknown_distance
272287
When executing query:
273288
"""
274289
MATCH (v:player) RETURN v LIMIT $p6
@@ -345,6 +360,28 @@ Feature: Parameter
345360
| v |
346361
| BAD_TYPE |
347362
| BAD_TYPE |
363+
When executing query:
364+
"""
365+
GET SUBGRAPH FROM 'Tim Duncan' WHERE like.likeness > $p10 YIELD edges AS e
366+
"""
367+
Then the result should be, in any order:
368+
| e |
369+
| [[: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}]] |
370+
| [[:like "Tony Parker"->"Manu Ginobili" @0 {likeness: 95}], [:like "Dejounte Murray"->"Manu Ginobili" @0 {likeness: 99}], [:like "Dejounte Murray"->"Tony Parker" @0 {likeness: 99}]] |
371+
When executing query:
372+
"""
373+
FIND ALL PATH FROM 'Tim Duncan' TO 'Tony Parker' OVER like WHERE like.likeness > $p10-1 YIELD path AS p
374+
"""
375+
Then the result should be, in any order, with relax comparison:
376+
| p |
377+
| <("Tim Duncan")-[:like@0 {likeness: 95}]->("Tony Parker")> |
378+
| <("Tim Duncan")-[:like@0 {likeness: 95}]->("Manu Ginobili")-[:like@0 {likeness: 90}]->("Tim Duncan")-[:like@0 {likeness: 95}]->("Tony Parker")> |
379+
When executing query:
380+
"""
381+
FIND ALL PATH FROM 'Tim Duncan' TO 'Tony Parker' OVER like WHERE like.likeness > $p5[10] YIELD path AS p
382+
"""
383+
Then the result should be, in any order:
384+
| p |
348385
349386
Scenario: [param-test-013] DML
350387
Given an empty graph

0 commit comments

Comments
 (0)