From 83184ba72d7b88f812575dcd50b81066e0c1ec3f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dani=C3=ABl=20van=20Eeden?= Date: Fri, 21 Jun 2024 11:17:17 +0200 Subject: [PATCH 1/5] SELECT: Update EBNF for partitioning --- sql-statements/sql-statement-select.md | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/sql-statements/sql-statement-select.md b/sql-statements/sql-statement-select.md index 1e101c27e9a3a..5d72086c18e7e 100644 --- a/sql-statements/sql-statement-select.md +++ b/sql-statements/sql-statement-select.md @@ -31,7 +31,24 @@ SelectStmtOpts ::= SelectStmtStraightJoin TableRefsClause ::= - TableRef AsOfClause? ( ',' TableRef AsOfClause? )* + TableRef ( ',' TableRef )* + +TableRef ::= + TableFactor +| JoinTable + +TableFactor ::= + TableName ( "PARTITION" "(" PartitionName ")" )? ("AS" TableAlias)? AsOfClause? TableSample? + +JoinTable ::= + ( TableRef ( ("INNER" | "CROSS")? "JOIN" | "STRAIGHT_JOIN" ) TableFactor JoinClause? + | TableRef ( ("LEFT" | "RIGHT") "OUTER"? "JOIN" ) TableRef JoinClause + | TableRef "NATURAL" "INNER"? ("LEFT" | "RIGHT") "OUTER"? "JOIN" ) TableFactor + + +JoinClause ::= + ("ON" Expression + | "USING" "(" ColumnNameList ")" ) AsOfClause ::= 'AS' 'OF' 'TIMESTAMP' Expression @@ -50,7 +67,7 @@ TableList ::= WindowClause ::= "WINDOW" WindowDefinition ("," WindowDefinition)* -TableSampleOpt ::= +TableSample ::= 'TABLESAMPLE' 'REGIONS' '(' ')' ``` From 5efa9c65fafe418996cfaeed4050411200bc2d0f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dani=C3=ABl=20van=20Eeden?= Date: Fri, 21 Jun 2024 11:40:21 +0200 Subject: [PATCH 2/5] Also define WhereClause,GroupByClause and OrderBy --- sql-statements/sql-statement-select.md | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/sql-statements/sql-statement-select.md b/sql-statements/sql-statement-select.md index 5d72086c18e7e..2266d6696fe57 100644 --- a/sql-statements/sql-statement-select.md +++ b/sql-statements/sql-statement-select.md @@ -45,7 +45,6 @@ JoinTable ::= | TableRef ( ("LEFT" | "RIGHT") "OUTER"? "JOIN" ) TableRef JoinClause | TableRef "NATURAL" "INNER"? ("LEFT" | "RIGHT") "OUTER"? "JOIN" ) TableFactor - JoinClause ::= ("ON" Expression | "USING" "(" ColumnNameList ")" ) @@ -64,6 +63,15 @@ SelectLockOpt ::= TableList ::= TableName ( ',' TableName )* +WhereClause ::= + "WHERE" Expression ( ("AND" | "OR") Expression)* + +GroupByClause ::= + "GROUP BY" Expression + +OrderBy ::= + "ORDER BY" Expression + WindowClause ::= "WINDOW" WindowDefinition ("," WindowDefinition)* From e0613c50d86bf6336d1cad64700d4c62ca64cbd2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dani=C3=ABl=20van=20Eeden?= Date: Fri, 21 Jun 2024 12:06:59 +0200 Subject: [PATCH 3/5] Update based on review --- sql-statements/sql-statement-select.md | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/sql-statements/sql-statement-select.md b/sql-statements/sql-statement-select.md index 2266d6696fe57..75912b486f672 100644 --- a/sql-statements/sql-statement-select.md +++ b/sql-statements/sql-statement-select.md @@ -38,12 +38,13 @@ TableRef ::= | JoinTable TableFactor ::= - TableName ( "PARTITION" "(" PartitionName ")" )? ("AS" TableAlias)? AsOfClause? TableSample? + TableName ( "PARTITION" "(" Identifier ("," Identifier)* ")" )? ("AS" TableAlias)? AsOfClause? TableSample? JoinTable ::= - ( TableRef ( ("INNER" | "CROSS")? "JOIN" | "STRAIGHT_JOIN" ) TableFactor JoinClause? + ( TableRef ("INNER" | "CROSS")? "JOIN" ) TableRef JoinClause? + ( TableRef "STRAIGHT_JOIN" TableRef "ON" Expression | TableRef ( ("LEFT" | "RIGHT") "OUTER"? "JOIN" ) TableRef JoinClause - | TableRef "NATURAL" "INNER"? ("LEFT" | "RIGHT") "OUTER"? "JOIN" ) TableFactor + | TableRef "NATURAL" ("LEFT" | "RIGHT") "OUTER"? "JOIN" ) JoinClause ::= ("ON" Expression @@ -64,7 +65,7 @@ TableList ::= TableName ( ',' TableName )* WhereClause ::= - "WHERE" Expression ( ("AND" | "OR") Expression)* + "WHERE" Expression GroupByClause ::= "GROUP BY" Expression From 633dee5dbf7320da1ad3601c76815c18ae3e46da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dani=C3=ABl=20van=20Eeden?= Date: Fri, 21 Jun 2024 12:07:41 +0200 Subject: [PATCH 4/5] Update sql-statements/sql-statement-select.md Co-authored-by: kennytm --- sql-statements/sql-statement-select.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sql-statements/sql-statement-select.md b/sql-statements/sql-statement-select.md index 75912b486f672..ede7cd7dbd453 100644 --- a/sql-statements/sql-statement-select.md +++ b/sql-statements/sql-statement-select.md @@ -68,10 +68,10 @@ WhereClause ::= "WHERE" Expression GroupByClause ::= - "GROUP BY" Expression + "GROUP" "BY" Expression OrderBy ::= - "ORDER BY" Expression + "ORDER" "BY" Expression WindowClause ::= "WINDOW" WindowDefinition ("," WindowDefinition)* From 05ff289c15343ead941d54dfd15cc32040eb1054 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dani=C3=ABl=20van=20Eeden?= Date: Mon, 26 Aug 2024 09:38:35 +0200 Subject: [PATCH 5/5] Update JoinTable --- sql-statements/sql-statement-select.md | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/sql-statements/sql-statement-select.md b/sql-statements/sql-statement-select.md index ede7cd7dbd453..b99a68709c5bb 100644 --- a/sql-statements/sql-statement-select.md +++ b/sql-statements/sql-statement-select.md @@ -41,10 +41,13 @@ TableFactor ::= TableName ( "PARTITION" "(" Identifier ("," Identifier)* ")" )? ("AS" TableAlias)? AsOfClause? TableSample? JoinTable ::= - ( TableRef ("INNER" | "CROSS")? "JOIN" ) TableRef JoinClause? - ( TableRef "STRAIGHT_JOIN" TableRef "ON" Expression - | TableRef ( ("LEFT" | "RIGHT") "OUTER"? "JOIN" ) TableRef JoinClause - | TableRef "NATURAL" ("LEFT" | "RIGHT") "OUTER"? "JOIN" ) + TableRef + ( + ("INNER" | "CROSS")? "JOIN" TableRef JoinClause? + | "STRAIGHT_JOIN" TableRef "ON" Expression + | ("LEFT" | "RIGHT") "OUTER"? "JOIN" TableRef JoinClause + | "NATURAL" ("LEFT" | "RIGHT") "OUTER"? "JOIN" TableFactor + ) JoinClause ::= ("ON" Expression