You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@asterixdb.apache.org by dl...@apache.org on 2021/01/27 01:07:55 UTC

[asterixdb] 09/11: [NO ISSUE][DOC] SQL++ EBNF doc cleanup

This is an automated email from the ASF dual-hosted git repository.

dlych pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/asterixdb.git

commit 13828a1debd397cb10293f57e4b0bb0291734b21
Author: Dmitry Lychagin <dm...@couchbase.com>
AuthorDate: Mon Jan 25 21:04:46 2021 -0800

    [NO ISSUE][DOC] SQL++ EBNF doc cleanup
    
    - user model changes: no
    - storage format changes: no
    - interface changes: no
    
    Details:
    - Cleanup and add missing elements to SQL++ EBNF doc
    
    Change-Id: Id54a67dc0d3747a0e3043378f992eb3e3497cbce
    Reviewed-on: https://asterix-gerrit.ics.uci.edu/c/asterixdb/+/9727
    Integration-Tests: Jenkins <je...@fulliautomatix.ics.uci.edu>
    Tested-by: Jenkins <je...@fulliautomatix.ics.uci.edu>
    Reviewed-by: Dmitry Lychagin <dm...@couchbase.com>
    Reviewed-by: Ali Alsuliman <al...@gmail.com>
---
 asterixdb/asterix-doc/src/main/grammar/sqlpp.ebnf  | 69 +++++++++-------------
 .../asterix-doc/src/main/markdown/sqlpp/2_expr.md  |  2 +
 .../asterix-doc/src/main/markdown/sqlpp/3_query.md |  4 ++
 .../src/main/markdown/sqlpp/7_ddl_dml.md           | 12 +++-
 4 files changed, 43 insertions(+), 44 deletions(-)

diff --git a/asterixdb/asterix-doc/src/main/grammar/sqlpp.ebnf b/asterixdb/asterix-doc/src/main/grammar/sqlpp.ebnf
index 45d7d6e..d338068 100644
--- a/asterixdb/asterix-doc/src/main/grammar/sqlpp.ebnf
+++ b/asterixdb/asterix-doc/src/main/grammar/sqlpp.ebnf
@@ -5,8 +5,7 @@ OperatorExpr ::= PathExpr
                  | OperatorExpr Operator OperatorExpr?
                  | OperatorExpr "BETWEEN" OperatorExpr "AND" OperatorExpr
 
-QuantifiedExpr::= ( "SOME" | "EVERY" ) Variable "IN" Expr ( "," Variable "in" Expr )*
-                         "SATISFIES" Expr ("END")?
+QuantifiedExpr::= ( "SOME" | "EVERY" ) Variable "IN" Expr ( "," Variable "IN" Expr )* "SATISFIES" Expr ("END")?
 
 PathExpr ::= PrimaryExpr ("." Identifier | "[" Expr (":" (Expr)? )? "]")*
 
@@ -35,13 +34,13 @@ FunctionCall ::= OrdinaryFunctionCall | AggregateFunctionCall | WindowFunctionCa
 
 OrdinaryFunctionCall ::= Identifier "(" Expr ("," Expr)* ")"
 
-AggregateFunctionCall ::= Identifier "(" ("DISTINCT")? Expr ")"
+AggregateFunctionCall ::= Identifier "(" ("DISTINCT")? Expr ")" ("FILTER" "(" "WHERE" Expr ")")?
 
 CaseExpr ::= SimpleCaseExpr | SearchedCaseExpr
 
 SimpleCaseExpr ::= "CASE" Expr ("WHEN" Expr "THEN" Expr)+ ("ELSE" Expr)? "END"
 
-SearchedCaseExpr ::= "CASE"("WHEN" Expr "THEN" Expr)+ ("ELSE" Expr)? "END"
+SearchedCaseExpr ::= "CASE" ("WHEN" Expr "THEN" Expr)+ ("ELSE" Expr)? "END"
 
 Constructor ::= ObjectConstructor | ArrayConstructor | MultisetConstructor
 
@@ -53,24 +52,26 @@ MultisetConstructor ::= "{{" Expr ("," Expr)* "}}"
 
 Query ::= (Expr | Selection) ";"
 
-Selection ::= WithClause? QueryBlock UnionOption* OrderByClause? LimitClause?
+Selection ::= WithClause? QueryBlock UnionOption* OrderByClause? ( LimitClause | OffsetClause )?
 
-QueryBlock ::=  SelectClause StreamGenerator?
-               |StreamGenerator SelectClause
+QueryBlock ::= SelectClause StreamGenerator?
+             | StreamGenerator SelectClause
 
 StreamGenerator::= FromClause LetClause? WhereClause? (GroupByClause LetClause? HavingClause?)?
 
-SelectClause ::= "SELECT" ("DISTINCT" | "ALL")? "VALUE" Expr
-               | "SELECT" ("DISTINCT" | "ALL")? ((Expr ("AS"? Identifier)?) | "*" | Identifier "." "*") ("," ((Expr ("AS"? Identifier)?) | "*" | Identifier "." "*"))*
+SelectClause ::= "SELECT" ("DISTINCT" | "ALL")? ( "VALUE" Expr | Projection ("," Projection)*)
+
+Projection ::= (Expr ("AS"? Identifier)?) | (VariableRef "." "*") | "*"
 
 FromClause ::= "FROM" FromTerm ("," FromTerm)*
 
-FromTerm ::= NamedExpr JoinStep*
+FromTerm ::= NamedExpr (JoinStep | UnnestStep)*
 
-NamedExpr ::= Expr
-             |Expr "AS"? Variable
+NamedExpr ::= Expr ("AS"? Variable)?
 
-JoinStep ::= ("INNER" | ("LEFT" "OUTER"?))? ("JOIN" NamedExpr "ON" Expr | "UNNEST" NamedExpr)
+JoinStep ::= ("INNER" | ( ( "LEFT" | "RIGHT" ) "OUTER"?))? "JOIN" NamedExpr "ON" Expr
+
+UnnestStep ::= ("INNER" | ( "LEFT" "OUTER"?))? "UNNEST" NamedExpr
 
 LetClause ::= "LET" Variable "=" Expr ("," Variable "=" Expr)*
 
@@ -86,9 +87,9 @@ GroupingElement ::=  GroupByExprPair
 
 OrdinaryGroupingSet ::= GroupByExprPair | ( "(" GroupByExprPair ( "," GroupByExprPair )* ")")
 
-GroupByExprPair ::= Expr ("AS"? Identifier)?
+GroupByExprPair ::= Expr ("AS"? Variable)?
 
-GroupAsClause ::= "GROUP AS" Identifier
+GroupAsClause ::= "GROUP AS" Variable
 
 HavingClause ::= "HAVING" Expr
 
@@ -96,11 +97,9 @@ Selection ::= WithClause? QueryBlock UnionOption* OrderByClause? ( LimitClause |
 
 UnionOption ::= "UNION ALL" (QueryBlock | Subquery)
 
-WithClause ::= "WITH" Identifier "AS" Expr
-                       ("," Identifier "AS" Expr)*
+WithClause ::= "WITH" Variable "AS" Expr ("," Variable "AS" Expr)*
 
-OrderbyClause ::= "ORDER BY" Expr ( "ASC" | "DESC" )?
-                       ( "," Expr ( "ASC" | "DESC" )? )*
+OrderbyClause ::= "ORDER BY" Expr ( "ASC" | "DESC" )? ( "," Expr ( "ASC" | "DESC" )? )*
 
 LimitClause ::= "LIMIT" Expr OffsetClause?
 
@@ -110,8 +109,7 @@ Subquery ::= "(" Selection ")"
 
 WindowFunctionCall ::= WindowFunctionType "(" WindowFunctionArguments ")" WindowFunctionOptions? "OVER" (Variable "AS")? "(" WindowDefinition")"
 
-WindowFunctionType ::= AggregateFunction
-                     | WindowFunction
+WindowFunctionType ::= AggregateFunction | WindowFunction
 
 WindowFunctionArguments ::=  ( ("DISTINCT")? Expr | (Expr ("," Expr ("," Expr)? )? )? )
 
@@ -126,11 +124,10 @@ WindowOrderClause ::= "ORDER" "BY" Expr ("ASC"|"DESC")? ("," Expr ("ASC" | "DESC
 WindowFrameClause ::= ("ROWS" | "RANGE" | "GROUPS") WindowFrameExtent
 
 WindowFrameExtent ::= ( ( "UNBOUNDED" | Expr ) "PRECEDING" | "CURRENT" "ROW" ) |
-"BETWEEN"( "UNBOUNDED" "PRECEDING" | "CURRENT" "ROW" | Expr ( "PRECEDING" | "FOLLOWING" ) )
-"AND" ( "UNBOUNDED" "FOLLOWING" | "CURRENT" "ROW" | Expr ( "PRECEDING" | "FOLLOWING" ) )
+      "BETWEEN" ( "UNBOUNDED" "PRECEDING" | "CURRENT" "ROW" | Expr ( "PRECEDING" | "FOLLOWING" ) )
+      "AND" ( "UNBOUNDED" "FOLLOWING" | "CURRENT" "ROW" | Expr ( "PRECEDING" | "FOLLOWING" ) )
 
-WindowFrameExclusion ::= "EXCLUDE" ( "CURRENT" "ROW" | "GROUP" | "TIES" |
-"NO" "OTHERS" )
+WindowFrameExclusion ::= "EXCLUDE" ( "CURRENT" "ROW" | "GROUP" | "TIES" | "NO" "OTHERS" )
 
 Stmnt::= (SingleStmnt ";")+ "EOF"
 
@@ -147,10 +144,6 @@ SingleStmnt ::= UseStmnt
 
 UseStmnt ::= "USE" Identifier
 
-FunctionDeclaration ::= "DELCARE" "FUNCTION" Identifier ParameterList "{" Expr "}"
-
-ParameterList ::= "(" ("VARIABLE" ("," "VARIABLE")*)?")"
-
 CreateStmnt ::= CreateDataverse
               | CreateType
               | CreateDataset
@@ -232,10 +225,12 @@ IndexType ::= "BTREE"
 
 CreateSynonym ::= "CREATE" "SYNONYM" QualifiedName "FOR" QualifiedName ("IF" "NOT" "EXISTS")?
 
-CreateFunction ::= "CREATE" ("OR" "REPLACE")? "FUNCTION" QualifiedName ("IF" "NOT" "EXISTS")? FunctionParameters
-                  ( ("{" Expr "}") | ExternalFunctionDef)
+FunctionDeclaration ::= "DECLARE" "FUNCTION" Identifier "(" ( (Variable ("," Variable)*) | "..." )? ")" "{" Expr "}"
+
+CreateFunction ::= "CREATE" ("OR" "REPLACE")? "FUNCTION" QualifiedName ("IF" "NOT" "EXISTS")? "(" FunctionParameters? ")"
+                  ( ("{" Expr "}") | ExternalFunctionDef )
 
-FunctionParameters ::= "(" ("VARIABLE" (":" TypeExpr)? ("," "VARIABLE" (":" TypeExpr)? )* )? ")"
+FunctionParameters ::=  ( Variable ((":")? TypeExpr)? ("," Variable ((":")? TypeExpr)? )* ) | "..."
 
 ExternalFunctionDef ::= ("RETURNS" TypeExpr)? "AS" StringLiteral ("," StringLiteral )* "AT" QualifiedName ("WITH" ObjectConstructor)?
 
@@ -244,7 +239,7 @@ DropStmnt ::= "DROP" ("DATAVERSE" Identifier
                      | "INDEX" DoubleQualifiedName
                      | "FUNCTION" FunctionSignature ) ("IF" "EXISTS")?
 
-FunctionSignature ::= QualifiedName ( FunctionParameters | ( "(" IntegerLiteral ")" ) | ("@" IntegerLiteral) )
+FunctionSignature ::= QualifiedName ( ( "(" ( FunctionParameters? | IntegerLiteral ) ")" ) | ("@" IntegerLiteral) )
 
 LoadStmnt ::= "LOAD" "DATASET" QualifiedName "USING" AdapterName Configuration ("PRE-SORTED")?
 
@@ -255,11 +250,3 @@ UpsertStmnt ::= "UPSERT" "INTO" QualifiedName Query
 DeleteStmnt ::= "DELETE" "FROM" QualifiedName (("AS")? Variable)? ("WHERE" Expr)?
 
 SetStmnt ::= "SET" Identifier StringLiteral
-
-
-
-
-
-
-
-
diff --git a/asterixdb/asterix-doc/src/main/markdown/sqlpp/2_expr.md b/asterixdb/asterix-doc/src/main/markdown/sqlpp/2_expr.md
index 9979570..ae203bf 100644
--- a/asterixdb/asterix-doc/src/main/markdown/sqlpp/2_expr.md
+++ b/asterixdb/asterix-doc/src/main/markdown/sqlpp/2_expr.md
@@ -400,6 +400,8 @@ expression with the given parameter bindings; the parameter value bindings can t
 Note that Window functions, and aggregate functions used as window functions, have a more complex syntax.
 Window function calls are described in the section on [Window Queries](#Over_clauses).
 
+Also note that FILTER expressions can only be specified when calling [Aggregation Pseudo-Functions](#Aggregation_PseudoFunctions). 
+
 The following example is a function call expression whose value is 8.
 
 ##### Example
diff --git a/asterixdb/asterix-doc/src/main/markdown/sqlpp/3_query.md b/asterixdb/asterix-doc/src/main/markdown/sqlpp/3_query.md
index 8076140..43445ed 100644
--- a/asterixdb/asterix-doc/src/main/markdown/sqlpp/3_query.md
+++ b/asterixdb/asterix-doc/src/main/markdown/sqlpp/3_query.md
@@ -23,6 +23,8 @@
 ### SelectClause
 **![](../images/diagrams/SelectClause.png)**
 
+### Projection
+**![](../images/diagrams/Projection.png)**
 
 ##### Synonyms for `VALUE`: `ELEMENT`, `RAW`
 ---
@@ -322,6 +324,8 @@ Result:
 ### JoinStep
 **![](../images/diagrams/JoinStep.png)**
 
+### UnnestStep
+**![](../images/diagrams/UnnestStep.png)**
 
 ##### Synonyms for `UNNEST`: `CORRELATE`, `FLATTEN`
 ---
diff --git a/asterixdb/asterix-doc/src/main/markdown/sqlpp/7_ddl_dml.md b/asterixdb/asterix-doc/src/main/markdown/sqlpp/7_ddl_dml.md
index 8ed266f..6bfac3b 100644
--- a/asterixdb/asterix-doc/src/main/markdown/sqlpp/7_ddl_dml.md
+++ b/asterixdb/asterix-doc/src/main/markdown/sqlpp/7_ddl_dml.md
@@ -51,9 +51,6 @@ The function named in the `DECLARE FUNCTION` statement is accessible only in the
 ### FunctionDeclaration
 **![](../images/diagrams/FunctionDeclaration.png)**
 
-### ParameterList
-**![](../images/diagrams/ParameterList.png)**
-
 ---
 The following is a simple example of a temporary function definition and its use.
 
@@ -513,6 +510,15 @@ The following is an example of CREATE FUNCTION statement that replaces an existi
          WHERE u.id = userId)[0]
      };
 
+The following is an example of CREATE FUNCTION statement that introduces a function with a variable number of arguments.
+The arguments are accessible in the function body via `args` array parameter.
+
+##### Example
+
+    CREATE FUNCTION strJoin(...) {
+        string_join(args, ",")
+    };
+
 External functions can also be loaded into Libraries via the [UDF API](../udf.html). Given
 an already loaded library `pylib`, a function `sentiment` mapping to a Python method `sent_model.sentiment` in `sentiment_mod`
 would be as follows