diff --git a/docs/zh/openmldb_sql/dql/GROUP_BY_CLAUSE.md b/docs/zh/openmldb_sql/dql/GROUP_BY_CLAUSE.md index 3c583948391..451d800e719 100644 --- a/docs/zh/openmldb_sql/dql/GROUP_BY_CLAUSE.md +++ b/docs/zh/openmldb_sql/dql/GROUP_BY_CLAUSE.md @@ -2,9 +2,9 @@ ## Syntax -```SQL -GroupByClause - ::= 'GROUP' 'BY' ByList +```yacc +group_by_clause: + GROUP BY group_by_specification ``` ## SQL语句模版 diff --git a/docs/zh/openmldb_sql/dql/HAVING_CLAUSE.md b/docs/zh/openmldb_sql/dql/HAVING_CLAUSE.md index 50c9cc8ae29..971fb58205d 100644 --- a/docs/zh/openmldb_sql/dql/HAVING_CLAUSE.md +++ b/docs/zh/openmldb_sql/dql/HAVING_CLAUSE.md @@ -4,9 +4,9 @@ Having 子句与 Where 子句作用类似.Having 子句过滤 GroupBy 后的各 ## Syntax -``` -HavingClause - ::= 'HAVING' Expression +```yacc +having_clause + HAVING bool_expression ``` ## SQL语句模版 diff --git a/docs/zh/openmldb_sql/dql/JOIN_CLAUSE.md b/docs/zh/openmldb_sql/dql/JOIN_CLAUSE.md index 6e74adc7928..64058ab1917 100644 --- a/docs/zh/openmldb_sql/dql/JOIN_CLAUSE.md +++ b/docs/zh/openmldb_sql/dql/JOIN_CLAUSE.md @@ -16,16 +16,16 @@ LAST JOIN 是 OpenMLDB SQL 拓展的 JOIN类型. 它的语法和 LEFT JOIN 基 ## Syntax -``` -join: - TableRef "LAST" "JOIN" TableRef [OrderByClause] "ON" Expression - | TableRef join_type "JOIN" TableRef "ON" Expression +```yacc +join_operation: + condition_join_operation -join_type: - 'LEFT' [OUTER] +condition_join_operation: + from_item LEFT [ OUTER ] JOIN from_item join_condition + | from_item LAST JOIN [ ORDER BY ordering_expression ] from_item join_condition -order_by_clause: - 'ORDER' 'BY' +join_condition: + ON bool_expression ``` ### 使用限制说明 diff --git a/docs/zh/openmldb_sql/dql/LIMIT_CLAUSE.md b/docs/zh/openmldb_sql/dql/LIMIT_CLAUSE.md index da009bdf4e7..f6135468253 100644 --- a/docs/zh/openmldb_sql/dql/LIMIT_CLAUSE.md +++ b/docs/zh/openmldb_sql/dql/LIMIT_CLAUSE.md @@ -4,9 +4,9 @@ Limit子句用于限制返回的结果条数。Limit支持接受一个参数, ## Syntax -```sql -LimitClause - ::= 'LIMIT' int_leteral +```yacc +limit_clause: + LIMIT numeric_expression ``` ## SQL语句模版 diff --git a/docs/zh/openmldb_sql/dql/NO_TABLE_SELECT_CLAUSE.md b/docs/zh/openmldb_sql/dql/NO_TABLE_SELECT_CLAUSE.md index c3cc6576688..fbdda689a0c 100644 --- a/docs/zh/openmldb_sql/dql/NO_TABLE_SELECT_CLAUSE.md +++ b/docs/zh/openmldb_sql/dql/NO_TABLE_SELECT_CLAUSE.md @@ -4,14 +4,8 @@ ## Syntax -```sql -NoTableSelectClause - ::= 'SELECT' SelectExprList -SelectExprList - ::= SelectExpr ( ',' SelectExpr )* -SelectExpr ::= ( Identifier '.' ( Identifier '.' )? )? '*' - | ( Expression | '{' Identifier Expression '}' ) ['AS' Identifier] - +```yacc +SELECT { expression [ [ AS ] alias ] } [, ...]; ``` ## SQL语句模版 diff --git a/docs/zh/openmldb_sql/dql/SELECT_INTO_STATEMENT.md b/docs/zh/openmldb_sql/dql/SELECT_INTO_STATEMENT.md index 3949dd5216e..1c50a4f8a82 100644 --- a/docs/zh/openmldb_sql/dql/SELECT_INTO_STATEMENT.md +++ b/docs/zh/openmldb_sql/dql/SELECT_INTO_STATEMENT.md @@ -5,21 +5,14 @@ ``` ## Syntax -```sql -SelectIntoStmt - ::= SelectStmt 'INTO' 'OUTFILE' filePath SelectIntoOptionList - -filePath - ::= string_literal -SelectIntoOptionList - ::= 'OPTIONS' '(' SelectInfoOptionItem (',' SelectInfoOptionItem)* ')' - -SelectInfoOptionItem - ::= 'DELIMITER' '=' string_literal - |'HEADER' '=' bool_literal - |'NULL_VALUE' '=' string_literal - |'FORMAT' '=' string_literal - |'MODE' '=' string_literal +```yacc +select_into_statement: + query INTO OUTFILE string_file_path + [ OPTIONS options_list ] + [ CONFIG options_list ] + +options_list: + ( { key = value } [, ...] ) ``` `SELECT INTO OUTFILE`分为三个部分。 diff --git a/docs/zh/openmldb_sql/dql/SELECT_STATEMENT.md b/docs/zh/openmldb_sql/dql/SELECT_STATEMENT.md index 2979873ae85..d846d567ef3 100644 --- a/docs/zh/openmldb_sql/dql/SELECT_STATEMENT.md +++ b/docs/zh/openmldb_sql/dql/SELECT_STATEMENT.md @@ -2,122 +2,102 @@ ## Syntax -### SelectStmt +### Syntax Notation -```yacc -SelectStmt - ::= WithClause ( NoTableSelectClause | SelectStmtFromTable) - -WithClause - ::= 'WITH' non_recursive_cte [, ...] - -non_recursive_cte - ::= cte_name 'AS' '(' SelectStmt ')' - -NoTableSelectClause - ::= 'SELECT' SelectExprList - -SelectStmtFromTable - ::= SelectStmtBasic 'FROM' TableRefs [WhereClause] [GroupByClause] [HavingClause] [WindowClause] [OrderByClause] [LimitClause] - -JoinClause - ::= TableRef JoinType 'JOIN' TableRef [OrderClause] 'ON' Expression -JoinType ::= 'LAST' - -WhereClause - ::= 'WHERE' Expression - -GroupByClause - ::= 'GROUP' 'BY' ByList - -HavingClause - ::= 'HAVING' Expression - -WindowClause - ::= ( 'WINDOW' WindowDefinition ( ',' WindowDefinition )* ) - -OrderByClause ::= 'ORDER' 'BY' ByList - -ByList ::= ByItem ( ',' ByItem )* - -ByItem ::= Expression Order - -Order ::= ( 'ASC' | 'DESC' )? - -WindowClauseOptional - ::= ( 'WINDOW' WindowDefinition ( ',' WindowDefinition )* )? -WindowDefinition - ::= WindowName 'AS' WindowSpec - -WindowSpec - ::= '(' WindowSpecDetails ')' - -WindowSpecDetails - ::= [ExistingWindowName] [WindowUnionClause] WindowPartitionClause WindowOrderByClause WindowFrameClause (WindowAttribute)* - -WindowUnionClause - :: = ( 'UNION' TableRefs) - -WindowPartitionClause - ::= ( 'PARTITION' 'BY' ByList ) - -WindowOrderByClause - ::= ( 'ORDER' 'BY' ByList ) +- `[ expr ]`: 中括号,可选部分 +- `{}`: 手动分组 +- `a | b`: 逻辑或,表示 `a` 或 `b` +- `...`: 重复之前的部分, 重复次数 >= 0 +- 大写变量,例如 `WITH`, 表示 SQL 关键词 "WITH" +- 小写变量, 例如 `query`, 可以拓展成特定语法结构 -WindowFrameClause - ::= ( WindowFrameUnits WindowFrameBounds [WindowFrameMaxSize] ) +### Select Statement -WindowFrameUnits - ::= 'ROWS' - | 'ROWS_RANGE' - -WindowFrameBounds - ::= 'BETWEEN' WindowFrameBound 'AND' WindowFrameBound - -WindowFrameBound - ::= ( 'UNBOUNDED' | NumLiteral | IntervalLiteral ) ['OPEN'] 'PRECEDING' - | 'CURRENT' 'ROW' - -WindowAttribute - ::= WindowExcludeCurrentTime - | WindowExcludeCurrentRow - | WindowInstanceNotInWindow - -WindowExcludeCurrentTime - ::= 'EXCLUDE' 'CURRENT_TIME' - -WindowExcludeCurrentRow - ::= 'EXCLUDE' 'CURRENT_ROW' - -WindowInstanceNotInWindow - :: = 'INSTANCE_NOT_IN_WINDOW' - -WindowFrameMaxSize - :: = 'MAXSIZE' NumLiteral -``` - -### SelectExprList - -```sql -SelectExprList - ::= SelectExpr ( ',' SelectExpr )* -SelectExpr ::= ( Identifier '.' ( Identifier '.' )? )? '*' - | ( Expression | '{' Identifier Expression '}' ) ['AS' Identifier] - -``` - -### TableRefs - -```sql -TableRefs - ::= EscapedTableRef ( ',' EscapedTableRef )* -TableRef ::= TableFactor - | JoinClause -TableFactor - ::= TableName [TableAsName] - | '(' ( ( SelectStmt ) ')' TableAsName | TableRefs ')' ) -TableAsName - ::= 'AS'? Identifier +```yacc +query_statement: + query [ CONFIG ( { key = value }[, ...] )] + +query: + [ WITH {non_recursive_cte}[, ...] ] + { select | ( query ) | set_operation } + [ ORDER BY ordering_expression ] + [ LIMIT count ] + +select: + SELECT select_list + [ FROM from_item ] + [ WHERE bool_expression ] + [ GROUP BY group_by_specification ] + [ HAVING bool_expression ] + [ window_clause ] + +set_operation: + query set_operator query + +non_recursive_cte: + cte_name AS ( query ) + +set_operator: + UNION ALL + +from_item: + table_name [ as_alias ] + | { join_operation | ( join_operation ) } + | ( query ) [ as_alias ] + | cte_name [ as_alias ] + +as_alias: + [ AS ] alias_name + +join_operation: + condition_join_operation + +condition_join_operation: + from_item LEFT [ OUTER ] JOIN from_item join_condition + | from_item LAST JOIN [ ORDER BY ordering_expression ] from_item join_condition + +join_condition: + ON bool_expression + +window_clause: + WINDOW named_window_expression [, ...] + +named_window_expression: + named_window AS { named_window | ( window_specification ) } + +window_specification: + [ UNION ( from_item [, ...] ) ] + PARTITION BY expression [ ORDER BY ordering_expression ] + window_frame_clause [ window_attr [, ...] ] + +window_frame_clause: + frame_units BETWEEN frame_bound AND frame_bound [ MAXSIZE numeric_expression ] ) + +frame_unit: + ROWS + | ROWS_RANGE + +frame_boud: + { UNBOUNDED | numeric_expression | interval_expression } [ OPEN ] PRECEDING + | CURRENT ROW + +window_attr: + EXCLUDE CURRENT_TIME + | EXCLUDE CURRENT_ROW + | INSTANCE_NOT_IN_WINDOW + +// each item in select list is one of: +// - * +// - expression.* +// - expression +select_list: + { select_all | select_expression } [, ...] + +select_all: + [ expression. ]* + +select_expression: + expression [ [ AS ] alias ] ``` ## SELECT语句元素 diff --git a/docs/zh/openmldb_sql/dql/WHERE_CLAUSE.md b/docs/zh/openmldb_sql/dql/WHERE_CLAUSE.md index 640b9954c56..adfb6e7ce0f 100644 --- a/docs/zh/openmldb_sql/dql/WHERE_CLAUSE.md +++ b/docs/zh/openmldb_sql/dql/WHERE_CLAUSE.md @@ -4,10 +4,9 @@ Where 子句用于设置过滤条件,查询结果中只会包含满足条件 ## Syntax -```sql -WhereClause - ::= 'WHERE' Expression - +```yacc +where_clause: + WHERE bool_expression ``` ## SQL语句模版 diff --git a/docs/zh/openmldb_sql/dql/WINDOW_CLAUSE.md b/docs/zh/openmldb_sql/dql/WINDOW_CLAUSE.md index a206c92fb8c..e2e23864aed 100644 --- a/docs/zh/openmldb_sql/dql/WINDOW_CLAUSE.md +++ b/docs/zh/openmldb_sql/dql/WINDOW_CLAUSE.md @@ -2,58 +2,33 @@ ## Syntax -```sql -WindowClauseOptional - ::= ( 'WINDOW' WindowDefinition ( ',' WindowDefinition )* )? - -WindowDefinition - ::= WindowName 'AS' WindowSpec - -WindowSpec - ::= '(' WindowSpecDetails ')' - -WindowSpecDetails - ::= [ExistingWindowName] [WindowUnionClause] WindowPartitionClause WindowOrderByClause WindowFrameClause (WindowAttribute)* - -WindowUnionClause - :: = ( 'UNION' TableRefs) - -WindowPartitionClause - ::= ( 'PARTITION' 'BY' ByList ) - -WindowOrderByClause - ::= ( 'ORDER' 'BY' ByList ) - -WindowFrameClause - ::= ( WindowFrameUnits WindowFrameBounds [WindowFrameMaxSize] ) - -WindowFrameUnits - ::= 'ROWS' - | 'ROWS_RANGE' - -WindowFrameBounds - ::= 'BETWEEN' WindowFrameBound 'AND' WindowFrameBound +```yacc +window_clause: + WINDOW named_window_expression [, ...] -WindowFrameBound - ::= ( 'UNBOUNDED' | NumLiteral | IntervalLiteral ) ['OPEN'] 'PRECEDING' - | 'CURRENT' 'ROW' +named_window_expression: + named_window AS { named_window | ( window_specification ) } -WindowAttribute - ::= WindowExcludeCurrentTime - | WindowExcludeCurrentRow - | WindowInstanceNotInWindow +window_specification: + [ UNION ( from_item [, ...] ) ] + PARTITION BY expression [ ORDER BY ordering_expression ] + window_frame_clause [ window_attr [, ...] ] -WindowExcludeCurrentTime - ::= 'EXCLUDE' 'CURRENT_TIME' +window_frame_clause: + frame_units BETWEEN frame_bound AND frame_bound [ MAXSIZE numeric_expression ] ) -WindowExcludeCurrentRow - ::= 'EXCLUDE' 'CURRENT_ROW' +frame_unit: + ROWS + | ROWS_RANGE -WindowInstanceNotInWindow - :: = 'INSTANCE_NOT_IN_WINDOW' +frame_boud: + { UNBOUNDED | numeric_expression | interval_expression } [ OPEN ] PRECEDING + | CURRENT ROW -WindowFrameMaxSize - :: = 'MAXSIZE' NumLiteral +window_attr: + EXCLUDE CURRENT_TIME + | EXCLUDE CURRENT_ROW + | INSTANCE_NOT_IN_WINDOW ``` *窗口调用函数*实现了类似于聚合函数的功能。 不同的是,窗口调用函数不需要将查询结果打包成一行输出—在查询输出中,每一行都是分开的。 然而,窗口调用函数可以扫描所有的行,根据窗口调用函数的分组规范(`PARTITION BY`列), 这些行可能会是当前行所在组的一部分。一个窗口调用函数的语法是下列之一: diff --git a/docs/zh/openmldb_sql/dql/WITH_CLAUSE.md b/docs/zh/openmldb_sql/dql/WITH_CLAUSE.md index d64d83823da..1e1f86b749c 100644 --- a/docs/zh/openmldb_sql/dql/WITH_CLAUSE.md +++ b/docs/zh/openmldb_sql/dql/WITH_CLAUSE.md @@ -4,11 +4,15 @@ OpenMLDB 在 0.7.2 开始支持 WITH 子句。WITH 子句借鉴了 [WITH Clause ## Syntax -``` -'WITH' non_recursive_cte [, ... ] - -non_recursive_cte - ::= cte_name 'AS' '(' SelectStmt ')' +```yacc +query: + [ WITH {non_recursive_cte}[, ...] ] + { select | ( query ) | set_operation } + [ ORDER BY ordering_expression ] + [ LIMIT count ] + +non_recursive_cte: + cte_name AS ( query ) ``` ## Description