Skip to content

Commit

Permalink
Fix bug #1337 from ent (#4740)
Browse files Browse the repository at this point in the history
* Return an semantic error if no tag is found for a property while validating a match.

* Return an semantic error if no tag is found for a property while validating a match.

* Add a tck case for the fixed bug.

* commented out unused codes.

* add tag in tck cases

* fixing tck

* updated tck cases to add missing cases that are supposed to be there.

* Return an semantic error if no tag is found for a property while validating a match.

* Add a tck case for the fixed bug.

* commented out unused codes.

* add tag in tck cases

* fixing tck

* updated tck cases to add missing cases that are supposed to be there.

* update

* update tck case.

Co-authored-by: Sophie <[email protected]>
  • Loading branch information
xtcyclist and Sophie-Xie authored Oct 24, 2022
1 parent 47d6921 commit 0d5d063
Show file tree
Hide file tree
Showing 10 changed files with 48 additions and 22 deletions.
15 changes: 14 additions & 1 deletion src/graph/validator/MatchValidator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,12 @@ Status MatchValidator::buildNodeInfo(const MatchPath *path,
auto alias = node->alias();
auto *props = node->props();
auto anonymous = false;
// if there exists some property with no tag, return a semantic error
if (props != nullptr) {
return Status::SemanticError("`%s:%s': No tag found for property.",
props->items()[0].first.c_str(),
props->items()[0].second->toString().c_str());
}
if (node->labels() != nullptr) {
auto &labels = node->labels()->labels();
for (const auto &label : labels) {
Expand All @@ -213,11 +219,18 @@ Status MatchValidator::buildNodeInfo(const MatchPath *path,
nodeAliases.emplace(alias, AliasType::kNode);
}
Expression *filter = nullptr;
/* Note(Xuntao): Commented out the following part. With the current parser,
if no tag is given in match clauses, node->props() is not nullptr but
node-labels() is. This is not supposed to be valid.
*/
/*
if (props != nullptr) {
auto result = makeNodeSubFilter(const_cast<MapExpression *>(props), "*");
NG_RETURN_IF_ERROR(result);
filter = result.value();
} else if (node->labels() != nullptr && !node->labels()->labels().empty()) {
} else
*/
if (node->labels() != nullptr && !node->labels()->labels().empty()) {
const auto &labels = node->labels()->labels();
for (const auto &label : labels) {
auto result = makeNodeSubFilter(label->props(), *label->label());
Expand Down
9 changes: 2 additions & 7 deletions tests/tck/features/match/Base.IntVid.feature
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ Feature: Basic match
| "serve" | "Cavaliers" |
When executing query:
"""
MATCH (v1:player{name: "LeBron James"}) -[r:serve]-> (v2 {name: "Cavaliers"})
MATCH (v1:player{name: "LeBron James"}) -[r:serve]-> (v2:team{name: "Cavaliers"})
RETURN type(r) AS Type, v2.team.name AS Name
"""
Then the result should be, in any order:
Expand All @@ -137,7 +137,7 @@ Feature: Basic match
| "serve" | "Cavaliers" |
When executing query:
"""
MATCH (v1:player{name: "LeBron James"}) -[r:serve]-> (v2 {name: "Cavaliers"})
MATCH (v1:player{name: "LeBron James"}) -[r:serve]-> (v2:team{name: "Cavaliers"})
WHERE r.start_year <= 2005 AND r.end_year >= 2005
RETURN r.start_year AS Start_Year, r.end_year AS Start_Year
"""
Expand Down Expand Up @@ -514,11 +514,6 @@ Feature: Basic match
MATCH (v) return v
"""
Then a ExecutionError should be raised at runtime: Scan vertices or edges need to specify a limit number, or limit number can not push down.
When executing query:
"""
MATCH (v{name: "Tim Duncan"}) return v
"""
Then a ExecutionError should be raised at runtime: Scan vertices or edges need to specify a limit number, or limit number can not push down.
When executing query:
"""
MATCH (v:player:bachelor) RETURN v
Expand Down
16 changes: 9 additions & 7 deletions tests/tck/features/match/Base.feature
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ Feature: Basic match
| "serve" | "Cavaliers" |
When executing query:
"""
MATCH (v1:player{name: "LeBron James"}) -[r:serve]-> (v2 {name: "Cavaliers"})
MATCH (v1:player{name: "LeBron James"}) -[r:serve]-> (v2:team{name: "Cavaliers"})
RETURN type(r) AS Type, v2.team.name AS Name
"""
Then the result should be, in any order:
Expand All @@ -175,7 +175,7 @@ Feature: Basic match
| "serve" | "Cavaliers" |
When executing query:
"""
MATCH (v1:player{name: "LeBron James"}) -[r:serve]-> (v2 {name: "Cavaliers"})
MATCH (v1:player{name: "LeBron James"}) -[r:serve]-> (v2:team{name: "Cavaliers"})
WHERE r.start_year <= 2005 AND r.end_year >= 2005
RETURN r.start_year AS Start_Year, r.end_year AS Start_Year
"""
Expand Down Expand Up @@ -624,11 +624,6 @@ Feature: Basic match
MATCH (v) return v
"""
Then a ExecutionError should be raised at runtime: Scan vertices or edges need to specify a limit number, or limit number can not push down.
When executing query:
"""
MATCH (v{name: "Tim Duncan"}) return v
"""
Then a ExecutionError should be raised at runtime: Scan vertices or edges need to specify a limit number, or limit number can not push down.
When executing query:
"""
MATCH (v:player:bachelor) RETURN v
Expand Down Expand Up @@ -761,3 +756,10 @@ Feature: Basic match
"""
Then the result should be, in any order, with relax comparison:
| id(v) |

Scenario: match_with_wrong_syntax
When executing query:
"""
MATCH (v{name: "Tim Duncan"}) return v
"""
Then a SemanticError should be raised at runtime: `name:"Tim Duncan"': No tag found for property.
2 changes: 1 addition & 1 deletion tests/tck/features/match/MatchById.IntVid.feature
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ Feature: Integer Vid Match By Id
| 'serve' | 'Lakers' |
When executing query:
"""
MATCH (v1) -[r:serve]-> (v2 {name: "Cavaliers"})
MATCH (v1) -[r:serve]-> (v2:team {name: "Cavaliers"})
WHERE id(v1) == hash("LeBron James")
RETURN type(r) AS Type, v2.team.name AS Name
"""
Expand Down
2 changes: 1 addition & 1 deletion tests/tck/features/match/MatchById.feature
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ Feature: Match By Id
| 'serve' | 'Lakers' |
When executing query:
"""
MATCH (v1) -[r:serve]-> (v2 {name: "Cavaliers"})
MATCH (v1) -[r:serve]-> (v2:team{name: "Cavaliers"})
WHERE id(v1) == "LeBron James"
RETURN type(r) AS Type, v2.team.name AS Name
"""
Expand Down
17 changes: 17 additions & 0 deletions tests/tck/features/match/PathExpr.feature
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,23 @@ Feature: Basic match
Background:
Given a graph with space named "nba"

Scenario: Tagless property
When executing query:
"""
match p = (v{name: "hello"})-->(v1{name: "hello"}) where id(v) == "kk" return p limit 1;
"""
Then a SemanticError should be raised at runtime: `name:"hello"': No tag found for property.
When executing query:
"""
match p = (v:player{name: "hello"})-->(v1{name: "world"}) where id(v) == "kk" return p limit 1;
"""
Then a SemanticError should be raised at runtime: `name:"world"': No tag found for property.
When executing query:
"""
match p = (v{name: "hello"})-->(v1:player{name: "world"}) where id(v) == "kk" return p limit 1;
"""
Then a SemanticError should be raised at runtime: `name:"hello"': No tag found for property.

Scenario: Undefined aliases
When executing query:
"""
Expand Down
3 changes: 1 addition & 2 deletions tests/tck/features/match/Scan.feature
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,8 @@ Feature: Match seek by scan
Then a ExecutionError should be raised at runtime: Scan vertices or edges need to specify a limit number, or limit number can not push down.
When executing query:
"""
MATCH (v{name: "Mary"})
MATCH (v:person)
RETURN v.student.name AS Name
LIMIT 3
"""
Then a ExecutionError should be raised at runtime: Scan vertices or edges need to specify a limit number, or limit number can not push down.

Expand Down
2 changes: 1 addition & 1 deletion tests/tck/features/match/VariableLengthPattern.feature
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ Feature: Variable length Pattern match (m to n)
Scenario: multi-steps and filter by node properties
When executing query:
"""
MATCH (v:player{name: 'Tim Duncan'})-[e1:like*1..2]-(v2{name: 'Tony Parker'})-[e2:serve]-(v3{name: 'Spurs'})
MATCH (v:player{name: 'Tim Duncan'})-[e1:like*1..2]-(v2:player{name: 'Tony Parker'})-[e2:serve]-(v3:team{name: 'Spurs'})
RETURN e1, e2
"""
Then the result should be, in any order, with relax comparison:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ Feature: Integer Vid Variable length Pattern match (m to n)
Scenario: Integer Vid multi-steps and filter by node properties
When executing query:
"""
MATCH (v:player{name: 'Tim Duncan'})-[e1:like*1..2]-(v2{name: 'Tony Parker'})-[e2:serve]-(v3{name: 'Spurs'})
MATCH (v:player{name: 'Tim Duncan'})-[e1:like*1..2]-(v2:player{name: 'Tony Parker'})-[e2:serve]-(v3:team{name: 'Spurs'})
RETURN e1, e2
"""
Then the result should be, in any order, with relax comparison:
Expand Down
2 changes: 1 addition & 1 deletion tests/tck/features/yield/parameter.feature
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ Feature: Parameter
| "Tony Parker" |
When executing query:
"""
MATCH (v:player)-[:like]->(n{name:$p7.a.b.c})
MATCH (v:player)-[:like]->(n:player{name:$p7.a.b.c})
RETURN n.player.name AS dst LIMIT $p7.a.b.d[0]
"""
Then the result should be, in any order:
Expand Down

0 comments on commit 0d5d063

Please sign in to comment.