From 798d48e6c78e72dd4995fa9596a006072eaadd12 Mon Sep 17 00:00:00 2001 From: jimingquan <6930445+nevermore3@users.noreply.github.com> Date: Tue, 26 Sep 2023 15:05:04 +0800 Subject: [PATCH] check illegal join statement (#5726) diable join clause yield agg --- src/parser/parser.yy | 10 ++++++++++ tests/tck/features/yield/join.feature | 21 +++++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/src/parser/parser.yy b/src/parser/parser.yy index f3d9847fef9..27042a80db4 100644 --- a/src/parser/parser.yy +++ b/src/parser/parser.yy @@ -1696,11 +1696,21 @@ yield_sentence $$ = s; } | KW_YIELD yield_columns join_clause { + if ($2->hasAgg()) { + delete($2); + delete($3); + throw nebula::GraphParser::syntax_error(@2, "Invalid use of aggregating function in yield clause."); + } auto *s = new YieldSentence($2); s->setJoinClause($3); $$ = s; } | KW_YIELD KW_DISTINCT yield_columns join_clause { + if ($3->hasAgg()) { + delete($3); + delete($4); + throw nebula::GraphParser::syntax_error(@2, "Invalid use of aggregating function in yield clause."); + } auto *s = new YieldSentence($3, true); s->setJoinClause($4); $$ = s; diff --git a/tests/tck/features/yield/join.feature b/tests/tck/features/yield/join.feature index d5be0b67053..787447adc94 100644 --- a/tests/tck/features/yield/join.feature +++ b/tests/tck/features/yield/join.feature @@ -7,6 +7,13 @@ Feature: join Given a graph with space named "nba" Scenario: invalid join + When executing query: + """ + $a = GO FROM 'Tim Duncan' OVER like YIELD id($$) as vid, edge as e; + $b = GO FROM 'Tony Parker' OVER like YIELD id($$) as vid, edge as e; + YIELD $a.vid AS id, $b.e AS e, count(*) FROM $a INNER JOIN $b ON $a.vid == $b.vid + """ + Then a SyntaxError should be raised at runtime: Invalid use of aggregating function in yield clause. near `$a.vid AS id, $b.e AS e, count(*)' When executing query: """ $a = GO FROM 'Tim Duncan' OVER like YIELD id($$) as vid, edge as e; @@ -359,3 +366,17 @@ Feature: join | [:like "Marco Belinelli"->"Tim Duncan" @0 {likeness: 55}] | [:like "Tony Parker"->"Tim Duncan" @0 {likeness: 95}] | | [:like "Marco Belinelli"->"Tim Duncan" @0 {likeness: 55}] | [:like "Tony Parker"->"Tim Duncan" @0 {likeness: 95}] | | [:like "Marco Belinelli"->"Tim Duncan" @0 {likeness: 55}] | [:like "Tony Parker"->"Tim Duncan" @0 {likeness: 95}] | + + Scenario: join limit + When executing query: + """ + $a = GO FROM "Tim Duncan" OVER like YIELD src(edge) AS src, edge AS e1; + $b = GO 2 STEPS FROM "Tony Parker" OVER like YIELD edge AS e2, dst(edge) AS dst; + YIELD $a.e1 AS e1, $b.e2 AS e2 from $a inner join $b ON $a.src == $b.dst | limit 10 + """ + Then the result should be, in any order, with relax comparison: + | e1 | e2 | + | [:like "Tim Duncan"->"Manu Ginobili" @0 {likeness: 95}] | [:like "LaMarcus Aldridge"->"Tim Duncan" @0 {likeness: 75}] | + | [:like "Tim Duncan"->"Tony Parker" @0 {likeness: 95}] | [:like "LaMarcus Aldridge"->"Tim Duncan" @0 {likeness: 75}] | + | [:like "Tim Duncan"->"Manu Ginobili" @0 {likeness: 95}] | [:like "Manu Ginobili"->"Tim Duncan" @0 {likeness: 90}] | + | [:like "Tim Duncan"->"Tony Parker" @0 {likeness: 95}] | [:like "Manu Ginobili"->"Tim Duncan" @0 {likeness: 90}] |