From 35b722f1e40731d7d89d52d2e51d50c05228fbfa Mon Sep 17 00:00:00 2001 From: nebula-bots <88429921+nebula-bots@users.noreply.github.com> Date: Mon, 24 Oct 2022 19:15:16 +0800 Subject: [PATCH] Fix bug #1337 from ent (#1511) * 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 <84560950+Sophie-Xie@users.noreply.github.com> Co-authored-by: Cheng Xuntao <7731943+xtcyclist@users.noreply.github.com> Co-authored-by: Sophie <84560950+Sophie-Xie@users.noreply.github.com> --- src/graph/validator/MatchValidator.cpp | 15 ++++++++++++++- tests/tck/features/match/Base.IntVid.feature | 9 ++------- tests/tck/features/match/Base.feature | 16 +++++++++------- .../tck/features/match/MatchById.IntVid.feature | 2 +- tests/tck/features/match/MatchById.feature | 2 +- tests/tck/features/match/PathExpr.feature | 17 +++++++++++++++++ tests/tck/features/match/Scan.feature | 3 +-- .../match/VariableLengthPattern.feature | 2 +- .../match/VariableLengthPattern.intVid.feature | 2 +- tests/tck/features/yield/parameter.feature | 2 +- 10 files changed, 48 insertions(+), 22 deletions(-) diff --git a/src/graph/validator/MatchValidator.cpp b/src/graph/validator/MatchValidator.cpp index 57efd109593..3ebb97f51a8 100644 --- a/src/graph/validator/MatchValidator.cpp +++ b/src/graph/validator/MatchValidator.cpp @@ -195,6 +195,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) { @@ -216,11 +222,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(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()); diff --git a/tests/tck/features/match/Base.IntVid.feature b/tests/tck/features/match/Base.IntVid.feature index dc4bff00b7b..20a43766a8f 100644 --- a/tests/tck/features/match/Base.IntVid.feature +++ b/tests/tck/features/match/Base.IntVid.feature @@ -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: @@ -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 """ @@ -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 diff --git a/tests/tck/features/match/Base.feature b/tests/tck/features/match/Base.feature index 470ceb802ca..d03688a0057 100644 --- a/tests/tck/features/match/Base.feature +++ b/tests/tck/features/match/Base.feature @@ -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: @@ -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 """ @@ -612,11 +612,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 @@ -749,3 +744,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. diff --git a/tests/tck/features/match/MatchById.IntVid.feature b/tests/tck/features/match/MatchById.IntVid.feature index 1bf44590933..38ff151f642 100644 --- a/tests/tck/features/match/MatchById.IntVid.feature +++ b/tests/tck/features/match/MatchById.IntVid.feature @@ -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 """ diff --git a/tests/tck/features/match/MatchById.feature b/tests/tck/features/match/MatchById.feature index ba600a169bf..6e1934920e6 100644 --- a/tests/tck/features/match/MatchById.feature +++ b/tests/tck/features/match/MatchById.feature @@ -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 """ diff --git a/tests/tck/features/match/PathExpr.feature b/tests/tck/features/match/PathExpr.feature index ffcd80d8d2f..078807c607d 100644 --- a/tests/tck/features/match/PathExpr.feature +++ b/tests/tck/features/match/PathExpr.feature @@ -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: """ diff --git a/tests/tck/features/match/Scan.feature b/tests/tck/features/match/Scan.feature index 3937e5ea91c..fc84d2f70f5 100644 --- a/tests/tck/features/match/Scan.feature +++ b/tests/tck/features/match/Scan.feature @@ -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. diff --git a/tests/tck/features/match/VariableLengthPattern.feature b/tests/tck/features/match/VariableLengthPattern.feature index 8d3b26edf05..c3c19133787 100644 --- a/tests/tck/features/match/VariableLengthPattern.feature +++ b/tests/tck/features/match/VariableLengthPattern.feature @@ -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: diff --git a/tests/tck/features/match/VariableLengthPattern.intVid.feature b/tests/tck/features/match/VariableLengthPattern.intVid.feature index 70721c32c77..238b5671671 100644 --- a/tests/tck/features/match/VariableLengthPattern.intVid.feature +++ b/tests/tck/features/match/VariableLengthPattern.intVid.feature @@ -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: diff --git a/tests/tck/features/yield/parameter.feature b/tests/tck/features/yield/parameter.feature index 58bd96d71c9..f7688f2d2c5 100644 --- a/tests/tck/features/yield/parameter.feature +++ b/tests/tck/features/yield/parameter.feature @@ -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: