asterixdb-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Dmitry Lychagin (Code Review)" <...@asterixdb.apache.org>
Subject Change in asterixdb[master]: [NO ISSUE] Reorganize OVER clause documentation
Date Wed, 26 Jun 2019 18:41:40 GMT
Dmitry Lychagin has submitted this change and it was merged. ( https://asterix-gerrit.ics.uci.edu/3464 )

Change subject: [NO ISSUE] Reorganize OVER clause documentation
......................................................................

[NO ISSUE] Reorganize OVER clause documentation

    - Move OVER clause into Query doc
    - Add link to window function calls from Expressions
    - Update links to OVER clause
    - Update ToCs with new location of OVER clause
    - Standardize IDs
    - Correct capitalization for admonition headings
    - Correct indentation in Window Function doc
    - Separate ToCs for SQL++ and AQL builtins

Change-Id: I683d024c56fcc55d67e1f87eec5494781bbcdede
Reviewed-on: https://asterix-gerrit.ics.uci.edu/3464
Sonar-Qube: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Contrib: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Tested-by: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Integration-Tests: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Reviewed-by: Dmitry Lychagin <dmitry.lychagin@couchbase.com>
---
M asterixdb/asterix-doc/pom.xml
M asterixdb/asterix-doc/src/main/markdown/builtins/0_toc.md
A asterixdb/asterix-doc/src/main/markdown/builtins/0_toc_aql.md
A asterixdb/asterix-doc/src/main/markdown/builtins/0_toc_common.md
A asterixdb/asterix-doc/src/main/markdown/builtins/0_toc_sqlpp.md
M asterixdb/asterix-doc/src/main/markdown/builtins/14_window.md
D asterixdb/asterix-doc/src/main/markdown/builtins/15_over.md
M asterixdb/asterix-doc/src/main/markdown/builtins/9_aggregate_sql.md
M asterixdb/asterix-doc/src/main/markdown/sqlpp/0_toc.md
M asterixdb/asterix-doc/src/main/markdown/sqlpp/2_expr.md
M asterixdb/asterix-doc/src/main/markdown/sqlpp/3_query.md
11 files changed, 496 insertions(+), 434 deletions(-)

Approvals:
  Jenkins: Verified; No violations found; ; Verified
  Dmitry Lychagin: Looks good to me, approved

Objections:
  Anon. E. Moose (1000171): Violations found



diff --git a/asterixdb/asterix-doc/pom.xml b/asterixdb/asterix-doc/pom.xml
index 963daec..83f82ad 100644
--- a/asterixdb/asterix-doc/pom.xml
+++ b/asterixdb/asterix-doc/pom.xml
@@ -55,10 +55,10 @@
                   <filelist dir="${project.basedir}/src/main/markdown/sqlpp" files="0_toc.md,1_intro.md,2_expr_title.md,2_expr.md,3_query_title.md,3_declare_dataverse.md,3_declare_function.md,3_query.md,4_error_title.md,4_error.md,5_ddl_head.md,5_ddl_dataset_index.md,5_ddl_function_removal.md,5_ddl_dml.md,appendix_1_title.md,appendix_1_keywords.md,appendix_2_title.md,appendix_2_parameters.md,appendix_2_index_only.md,appendix_3_title.md,appendix_3_resolution.md" />
                 </concat>
                 <concat destfile="${project.build.directory}/generated-site/markdown/sqlpp/builtins.md">
-                  <filelist dir="${project.basedir}/src/main/markdown/builtins" files="0_toc.md,1_numeric_common.md,1_numeric_delta.md,2_string_common.md,2_string_delta.md,3_binary.md,4_spatial.md,5_similarity.md,6_tokenizing.md,7_temporal.md,7_allens.md,8_record.md,9_aggregate_sql.md,10_comparison.md,11_type.md,13_conditional.md,12_misc.md,14_window.md,15_over.md" />
+                  <filelist dir="${project.basedir}/src/main/markdown/builtins" files="0_toc.md,0_toc_sqlpp.md,0_toc_common.md,1_numeric_common.md,1_numeric_delta.md,2_string_common.md,2_string_delta.md,3_binary.md,4_spatial.md,5_similarity.md,6_tokenizing.md,7_temporal.md,7_allens.md,8_record.md,9_aggregate_sql.md,10_comparison.md,11_type.md,13_conditional.md,12_misc.md,14_window.md" />
                 </concat>
                 <concat destfile="${project.build.directory}/generated-site/markdown/aql/builtins.md">
-                  <filelist dir="${project.basedir}/src/main/markdown/builtins" files="0_toc.md,1_numeric_common.md,1_numeric_delta.md,2_string_common.md,2_string_delta.md,3_binary.md,4_spatial.md,5_similarity.md,6_tokenizing.md,7_temporal.md,7_allens.md,8_record.md,9_aggregate_sql.md,10_comparison.md,11_type.md,13_conditional.md,12_misc.md" />
+                  <filelist dir="${project.basedir}/src/main/markdown/builtins" files="0_toc.md,0_toc_aql.md,0_toc_common.md,1_numeric_common.md,1_numeric_delta.md,2_string_common.md,2_string_delta.md,3_binary.md,4_spatial.md,5_similarity.md,6_tokenizing.md,7_temporal.md,7_allens.md,8_record.md,9_aggregate_sql.md,10_comparison.md,11_type.md,13_conditional.md,12_misc.md" />
                 </concat>
                 <concat destfile="${project.build.directory}/generated-site/markdown/datamodel.md">
                   <filelist dir="${project.basedir}/src/main/markdown/datamodel" files="datamodel_header.md,datamodel_primitive_common.md,datamodel_primitive_delta.md,datamodel_incomplete.md,datamodel_composite.md" />
diff --git a/asterixdb/asterix-doc/src/main/markdown/builtins/0_toc.md b/asterixdb/asterix-doc/src/main/markdown/builtins/0_toc.md
index 1a94577..c81c656 100644
--- a/asterixdb/asterix-doc/src/main/markdown/builtins/0_toc.md
+++ b/asterixdb/asterix-doc/src/main/markdown/builtins/0_toc.md
@@ -18,24 +18,3 @@
  !-->
 
 # Builtin Functions #
-
-## <a id="toc">Table of Contents</a> ##
-
-* [Numeric Functions](#NumericFunctions)
-* [String Functions](#StringFunctions)
-* [Binary Functions](#BinaryFunctions)
-* [Spatial Functions](#SpatialFunctions)
-* [Similarity Functions](#SimilarityFunctions)
-* [Tokenizing Functions](#TokenizingFunctions)
-* [Temporal Functions](#TemporalFunctions)
-* [Object Functions](#ObjectFunctions)
-* [Aggregate Functions (Array Functions)](#AggregateFunctions)
-* [Comparison Functions](#ComparisonFunctions)
-* [Type Functions](#TypeFunctions)
-* [Conditional Functions](#ConditionalFunctions)
-* [Miscellaneous Functions](#MiscFunctions)
-* [Window Functions](#WindowFunctions)
-* [OVER Clause (Window Function Calls)](#OverClause)
-
-The system provides various classes of functions to support operations on numeric, string, spatial, and temporal data.
-This document explains how to use these functions.
diff --git a/asterixdb/asterix-doc/src/main/markdown/builtins/0_toc_aql.md b/asterixdb/asterix-doc/src/main/markdown/builtins/0_toc_aql.md
new file mode 100644
index 0000000..f9e81dd
--- /dev/null
+++ b/asterixdb/asterix-doc/src/main/markdown/builtins/0_toc_aql.md
@@ -0,0 +1,34 @@
+<!--
+ ! Licensed to the Apache Software Foundation (ASF) under one
+ ! or more contributor license agreements.  See the NOTICE file
+ ! distributed with this work for additional information
+ ! regarding copyright ownership.  The ASF licenses this file
+ ! to you under the Apache License, Version 2.0 (the
+ ! "License"); you may not use this file except in compliance
+ ! with the License.  You may obtain a copy of the License at
+ !
+ !   http://www.apache.org/licenses/LICENSE-2.0
+ !
+ ! Unless required by applicable law or agreed to in writing,
+ ! software distributed under the License is distributed on an
+ ! "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ ! KIND, either express or implied.  See the License for the
+ ! specific language governing permissions and limitations
+ ! under the License.
+ !-->
+
+## <a id="toc">Table of Contents</a> ##
+
+* [Numeric Functions](#NumericFunctions)
+* [String Functions](#StringFunctions)
+* [Binary Functions](#BinaryFunctions)
+* [Spatial Functions](#SpatialFunctions)
+* [Similarity Functions](#SimilarityFunctions)
+* [Tokenizing Functions](#TokenizingFunctions)
+* [Temporal Functions](#TemporalFunctions)
+* [Object Functions](#ObjectFunctions)
+* [Aggregate Functions (Array Functions)](#AggregateFunctions)
+* [Comparison Functions](#ComparisonFunctions)
+* [Type Functions](#TypeFunctions)
+* [Conditional Functions](#ConditionalFunctions)
+* [Miscellaneous Functions](#MiscFunctions)
diff --git a/asterixdb/asterix-doc/src/main/markdown/builtins/0_toc_common.md b/asterixdb/asterix-doc/src/main/markdown/builtins/0_toc_common.md
new file mode 100644
index 0000000..c1a97cb
--- /dev/null
+++ b/asterixdb/asterix-doc/src/main/markdown/builtins/0_toc_common.md
@@ -0,0 +1,21 @@
+<!--
+ ! Licensed to the Apache Software Foundation (ASF) under one
+ ! or more contributor license agreements.  See the NOTICE file
+ ! distributed with this work for additional information
+ ! regarding copyright ownership.  The ASF licenses this file
+ ! to you under the Apache License, Version 2.0 (the
+ ! "License"); you may not use this file except in compliance
+ ! with the License.  You may obtain a copy of the License at
+ !
+ !   http://www.apache.org/licenses/LICENSE-2.0
+ !
+ ! Unless required by applicable law or agreed to in writing,
+ ! software distributed under the License is distributed on an
+ ! "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ ! KIND, either express or implied.  See the License for the
+ ! specific language governing permissions and limitations
+ ! under the License.
+ !-->
+
+The system provides various classes of functions to support operations on numeric, string, spatial, and temporal data.
+This document explains how to use these functions.
diff --git a/asterixdb/asterix-doc/src/main/markdown/builtins/0_toc_sqlpp.md b/asterixdb/asterix-doc/src/main/markdown/builtins/0_toc_sqlpp.md
new file mode 100644
index 0000000..7064b17
--- /dev/null
+++ b/asterixdb/asterix-doc/src/main/markdown/builtins/0_toc_sqlpp.md
@@ -0,0 +1,35 @@
+<!--
+ ! Licensed to the Apache Software Foundation (ASF) under one
+ ! or more contributor license agreements.  See the NOTICE file
+ ! distributed with this work for additional information
+ ! regarding copyright ownership.  The ASF licenses this file
+ ! to you under the Apache License, Version 2.0 (the
+ ! "License"); you may not use this file except in compliance
+ ! with the License.  You may obtain a copy of the License at
+ !
+ !   http://www.apache.org/licenses/LICENSE-2.0
+ !
+ ! Unless required by applicable law or agreed to in writing,
+ ! software distributed under the License is distributed on an
+ ! "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ ! KIND, either express or implied.  See the License for the
+ ! specific language governing permissions and limitations
+ ! under the License.
+ !-->
+
+## <a id="toc">Table of Contents</a> ##
+
+* [Numeric Functions](#NumericFunctions)
+* [String Functions](#StringFunctions)
+* [Binary Functions](#BinaryFunctions)
+* [Spatial Functions](#SpatialFunctions)
+* [Similarity Functions](#SimilarityFunctions)
+* [Tokenizing Functions](#TokenizingFunctions)
+* [Temporal Functions](#TemporalFunctions)
+* [Object Functions](#ObjectFunctions)
+* [Aggregate Functions (Array Functions)](#AggregateFunctions)
+* [Comparison Functions](#ComparisonFunctions)
+* [Type Functions](#TypeFunctions)
+* [Conditional Functions](#ConditionalFunctions)
+* [Miscellaneous Functions](#MiscFunctions)
+* [Window Functions](#WindowFunctions)
diff --git a/asterixdb/asterix-doc/src/main/markdown/builtins/14_window.md b/asterixdb/asterix-doc/src/main/markdown/builtins/14_window.md
index 64bcf17..adc5daa 100644
--- a/asterixdb/asterix-doc/src/main/markdown/builtins/14_window.md
+++ b/asterixdb/asterix-doc/src/main/markdown/builtins/14_window.md
@@ -28,7 +28,7 @@
 separate in the query output.
 
 All window functions must be used with an OVER clause.
-Refer to [OVER Clause](#OverClause) for details.
+Refer to [OVER Clauses](manual.html#Over_clauses) for details.
 
 Window functions cannot appear in the FROM clause clause or LIMIT clause.
 
@@ -52,9 +52,9 @@
 
 * Clauses:
 
-    * (Optional) [Window Partition Clause](#window-partition-clause).
+    * (Optional) [Window Partition Clause](manual.html#Window_partition_clause).
 
-    * (Required) [Window Order Clause](#window-order-clause).
+    * (Required) [Window Order Clause](manual.html#Window_order_clause).
 
 * Return Value:
 
@@ -122,13 +122,13 @@
   distinct tuples preceding this tuple in the current window partition, plus
   one.
 
-  The tuples are ordered by the window order clause.
-  If any tuples are tied, they will have the same rank.
+    The tuples are ordered by the window order clause.
+    If any tuples are tied, they will have the same rank.
 
-  For this function, when any tuples have the same rank, the rank of the next
-  tuple will be consecutive, so there will not be a gap in the sequence of
-  returned values.
-  For example, if there are three tuples ranked 2, the next dense rank is 3.
+    For this function, when any tuples have the same rank, the rank of the next
+    tuple will be consecutive, so there will not be a gap in the sequence of
+    returned values.
+    For example, if there are three tuples ranked 2, the next dense rank is 3.
 
 * Arguments:
 
@@ -136,9 +136,9 @@
 
 * Clauses:
 
-    * (Optional) [Window Partition Clause](#window-partition-clause).
+    * (Optional) [Window Partition Clause](manual.html#Window_partition_clause).
 
-    * (Required) [Window Order Clause](#window-order-clause).
+    * (Required) [Window Order Clause](manual.html#Window_order_clause).
 
 * Return Value:
 
@@ -209,8 +209,7 @@
         FIRST_VALUE(expr) [nulls-treatment] OVER (window-definition)
 
 * Returns the requested value from the first tuple in the current window
-  frame, where the window frame is specified by the [window
-  clause](#window-definition).
+  frame, where the window frame is specified by the window definition.
 
 * Arguments:
 
@@ -219,9 +218,9 @@
 
 * Modifiers:
 
-    * [Nulls Treatment](#nulls-treatment): (Optional) Determines how NULL or
-      MISSING values are treated when finding the first tuple in the window
-      frame.
+    * [Nulls Treatment](manual.html#Nulls_treatment): (Optional) Determines how
+      NULL or MISSING values are treated when finding the first tuple in the
+      window frame.
 
         - `IGNORE NULLS`: If the values for any tuples evaluate to NULL or
           MISSING, those tuples are ignored when finding the first tuple.
@@ -235,11 +234,11 @@
 
 * Clauses:
 
-    * (Optional) [Window Partition Clause](#window-partition-clause).
+    * (Optional) [Window Partition Clause](manual.html#Window_partition_clause).
 
-    * (Optional) [Window Order Clause](#window-order-clause).
+    * (Optional) [Window Order Clause](manual.html#Window_order_clause).
 
-    * (Optional) [Window Frame Clause](#window-frame-clause).
+    * (Optional) [Window Frame Clause](manual.html#Window_frame_clause).
 
 * Return Value:
 
@@ -346,9 +345,9 @@
 
 * Modifiers:
 
-    * [Nulls Treatment](#nulls-treatment): (Optional) Determines how NULL or
-      MISSING values are treated when finding the first tuple in the window
-      frame.
+    * [Nulls Treatment](manual.html#Nulls_treatment): (Optional) Determines how
+      NULL or MISSING values are treated when finding the first tuple in the
+      window frame.
 
         - `IGNORE NULLS`: If the values for any tuples evaluate to NULL or
           MISSING, those tuples are ignored when finding the first tuple.
@@ -362,9 +361,9 @@
 
 * Clauses:
 
-    * (Optional) [Window Partition Clause](#window-partition-clause).
+    * (Optional) [Window Partition Clause](manual.html#Window_partition_clause).
 
-    * (Required) [Window Order Clause](#window-order-clause).
+    * (Required) [Window Order Clause](manual.html#Window_order_clause).
 
 * Return Value:
 
@@ -449,9 +448,9 @@
 
 * Modifiers:
 
-    * [Nulls Treatment](#nulls-treatment): (Optional) Determines how NULL or
-      MISSING values are treated when finding the first tuple in the window
-      frame.
+    * [Nulls Treatment](manual.html#Nulls_treatment): (Optional) Determines how
+      NULL or MISSING values are treated when finding the first tuple in the
+      window frame.
 
         - `IGNORE NULLS`: If the values for any tuples evaluate to NULL or
           MISSING, those tuples are ignored when finding the first tuple.
@@ -465,11 +464,11 @@
 
 * Clauses:
 
-    * (Optional) [Window Partition Clause](#window-partition-clause).
+    * (Optional) [Window Partition Clause](manual.html#Window_partition_clause).
 
-    * (Optional) [Window Order Clause](#window-order-clause).
+    * (Optional) [Window Order Clause](manual.html#Window_order_clause).
 
-    * (Optional) [Window Frame Clause](#window-frame-clause).
+    * (Optional) [Window Frame Clause](manual.html#Window_frame_clause).
 
 * Return Value:
 
@@ -586,9 +585,9 @@
 
 * Modifiers:
 
-    * [Nulls Treatment](#nulls-treatment): (Optional) Determines how NULL or
-      MISSING values are treated when finding the first tuple in the window
-      frame.
+    * [Nulls Treatment](manual.html#Nulls_treatment): (Optional) Determines how
+      NULL or MISSING values are treated when finding the first tuple in the
+      window frame.
 
         - `IGNORE NULLS`: If the values for any tuples evaluate to NULL or
           MISSING, those tuples are ignored when finding the first tuple.
@@ -602,9 +601,9 @@
 
 * Clauses:
 
-    * (Optional) [Window Partition Clause](#window-partition-clause).
+    * (Optional) [Window Partition Clause](manual.html#Window_partition_clause).
 
-    * (Required) [Window Order Clause](#window-order-clause).
+    * (Required) [Window Order Clause](manual.html#Window_order_clause).
 
 * Return Value:
 
@@ -692,8 +691,8 @@
 
 * Modifiers:
 
-    * [Nth Val From](#nthval-from): (Optional) Determines where the function
-      starts counting the offset.
+    * [Nth Val From](manual.html#Nth_val_from): (Optional) Determines where the
+      function starts counting the offset.
 
         - `FROM FIRST`: Counting starts at the first tuple in the window frame.
           In this case, an offset of 1 is the first tuple in the window frame,
@@ -706,9 +705,9 @@
         The order of the tuples is determined by the window order clause.
         If this modifier is omitted, the default is `FROM FIRST`.
 
-    * [Nulls Treatment](#nulls-treatment): (Optional) Determines how NULL or
-      MISSING values are treated when finding the first tuple in the window
-      frame.
+    * [Nulls Treatment](manual.html#Nulls_treatment): (Optional) Determines how
+      NULL or MISSING values are treated when finding the first tuple in the
+      window frame.
 
         - `IGNORE NULLS`: If the values for any tuples evaluate to NULL or
           MISSING, those tuples are ignored when finding the first tuple.
@@ -722,11 +721,11 @@
 
 * Clauses:
 
-    * (Optional) [Window Partition Clause](#window-partition-clause).
+    * (Optional) [Window Partition Clause](manual.html#Window_partition_clause).
 
-    * (Optional) [Window Order Clause](#window-order-clause).
+    * (Optional) [Window Order Clause](manual.html#Window_order_clause).
 
-    * (Optional) [Window Frame Clause](#window-order-clause).
+    * (Optional) [Window Frame Clause](manual.html#Window_frame_clause).
 
 * Return Value:
 
@@ -915,9 +914,9 @@
 
 * Clauses:
 
-    * (Optional) [Window Partition Clause](#window-partition-clause).
+    * (Optional) [Window Partition Clause](manual.html#Window_partition_clause).
 
-    * (Required) [Window Order Clause](#window-order-clause).
+    * (Required) [Window Order Clause](manual.html#Window_order_clause).
 
 * Return Value:
 
@@ -990,9 +989,9 @@
 
 * Clauses:
 
-    * (Optional) [Window Partition Clause](#window-partition-clause).
+    * (Optional) [Window Partition Clause](manual.html#Window_partition_clause).
 
-    * (Required) [Window Order Clause](#window-order-clause).
+    * (Required) [Window Order Clause](manual.html#Window_order_clause).
 
 * Return Value:
 
@@ -1059,13 +1058,13 @@
 * Returns the rank of the current tuple – that is, the number of distinct
   tuples preceding this tuple in the current window partition, plus one.
 
-  The tuples are ordered by the window order clause.
-  If any tuples are tied, they will have the same rank.
+    The tuples are ordered by the window order clause.
+    If any tuples are tied, they will have the same rank.
 
-  When any tuples have the same rank, the rank of the next tuple will include
-  all preceding tuples, so there may be a gap in the sequence of returned
-  values.
-  For example, if there are three tuples ranked 2, the next rank is 5.
+    When any tuples have the same rank, the rank of the next tuple will include
+    all preceding tuples, so there may be a gap in the sequence of returned
+    values.
+    For example, if there are three tuples ranked 2, the next rank is 5.
 
 * Arguments:
 
@@ -1073,9 +1072,9 @@
 
 * Clauses:
 
-    * (Optional) [Window Partition Clause](#window-partition-clause).
+    * (Optional) [Window Partition Clause](manual.html#Window_partition_clause).
 
-    * (Required) [Window Order Clause](#window-order-clause).
+    * (Required) [Window Order Clause](manual.html#Window_order_clause).
 
 * Return Value:
 
@@ -1155,11 +1154,11 @@
 
 * Clauses:
 
-    * (Optional) [Window Partition Clause](#window-partition-clause).
+    * (Optional) [Window Partition Clause](manual.html#Window_partition_clause).
 
-    * (Optional) [Window Order Clause](#window-order-clause).
+    * (Optional) [Window Order Clause](manual.html#Window_order_clause).
 
-    * (Optional) [Window Frame Clause](#window-frame-clause).
+    * (Optional) [Window Frame Clause](manual.html#Window_frame_clause).
 
 * Return Value:
 
@@ -1231,8 +1230,9 @@
 * Returns a unique row number for every tuple in every window partition.
   In each window partition, the row numbering starts at 1.
 
-  The window order clause determines the sort order of the tuples.
-  If the window order clause is omitted, the return values may be unpredictable.
+    The window order clause determines the sort order of the tuples.
+    If the window order clause is omitted, the return values may be
+    unpredictable.
 
 * Arguments:
 
@@ -1240,9 +1240,9 @@
 
 * Clauses:
 
-    * (Optional) [Window Partition Clause](#window-partition-clause).
+    * (Optional) [Window Partition Clause](manual.html#Window_partition_clause).
 
-    * (Optional) [Window Order Clause](#window-order-clause).
+    * (Optional) [Window Order Clause](manual.html#Window_order_clause).
 
 * Return Value:
 
diff --git a/asterixdb/asterix-doc/src/main/markdown/builtins/15_over.md b/asterixdb/asterix-doc/src/main/markdown/builtins/15_over.md
deleted file mode 100644
index 67b409e..0000000
--- a/asterixdb/asterix-doc/src/main/markdown/builtins/15_over.md
+++ /dev/null
@@ -1,345 +0,0 @@
-<!--
- ! Licensed to the Apache Software Foundation (ASF) under one
- ! or more contributor license agreements.  See the NOTICE file
- ! distributed with this work for additional information
- ! regarding copyright ownership.  The ASF licenses this file
- ! to you under the Apache License, Version 2.0 (the
- ! "License"); you may not use this file except in compliance
- ! with the License.  You may obtain a copy of the License at
- !
- !   http://www.apache.org/licenses/LICENSE-2.0
- !
- ! Unless required by applicable law or agreed to in writing,
- ! software distributed under the License is distributed on an
- ! "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- ! KIND, either express or implied.  See the License for the
- ! specific language governing permissions and limitations
- ! under the License.
- !-->
-
-## <a id="OverClause">OVER Clause (Window Function Calls)</a> ##
-
-All window functions must have an OVER clause to define the window partitions,
-the order of tuples within those partitions, and the extent of the window frame.
-Some window functions take additional window options, which are specified by
-modifiers before the OVER clause.
-
-The query language has a dedicated set of window functions.
-Aggregate functions can also be used as window functions, when they are used
-with an OVER clause.
-
-### <a id="window-function-call">Window Function Call</a> ###
-
-    WindowFunctionCall ::= WindowFunctionType "(" WindowFunctionArguments ")"
-    (WindowFunctionOptions)? <OVER> (Variable <AS>)? "(" WindowClause ")"
-
-### <a id="window-function-type">Window Function Type</a> ###
-
-    WindowFunctionType ::= AggregateFunctions | WindowFunctions
-
-Refer to the [Aggregate Functions](#AggregateFunctions) section for a list of
-aggregate functions.
-
-Refer to the [Window Functions](#WindowFunctions) section for a list of window
-functions.
-
-### <a id="window-function-arguments">Window Function Arguments</a> ###
-
-    WindowFunctionArguments ::= ( (<DISTINCT>)? Expression |
-    (Expression ("," Expression ("," Expression)? )? )? )
-
-Refer to the [Aggregate Functions](#AggregateFunctions) section or the
-[Window Functions](#WindowFunctions) section for details of the arguments for
-individual functions.
-
-### <a id="window-function-options">Window Function Options</a> ###
-
-    WindowFunctionOptions ::= (NthValFrom)? (NullsTreatment)?
-
-Window function options cannot be used with [aggregate
-functions](#AggregateFunctions).
-
-Window function options can only be used with some [window
-functions](#WindowFunctions), as described below.
-
-#### <a id="nthval-from">Nth Val From</a> ####
-
-    NthValFrom ::= <FROM> ( <FIRST> | <LAST> )
-
-The **nth val from** modifier determines whether the computation begins at the
-first or last tuple in the window.
-
-This modifier can only be used with the `nth_value()` function.
-
-This modifier is optional.
-If omitted, the default setting is `FROM FIRST`.
-
-#### <a id="nulls-treatment">Nulls Treatment</a> ####
-
-    nulls-treatment ::= ( <RESPECT> | <IGNORE> ) <NULLS>
-
-The **nulls treatment** modifier determines whether NULL values are included in
-the computation, or ignored.
-MISSING values are treated the same way as NULL values.
-
-This modifier can only be used with the `first_value()`, `last_value()`,
-`nth_value()`, `lag()`, and `lead()` functions.
-
-This modifier is optional.
-If omitted, the default setting is `RESPECT NULLS`.
-
-### <a id="window-frame-variable">Window Frame Variable</a> ###
-
-The AS keyword enables you to specify an alias for the window frame contents.
-It introduces a variable which will be bound to the contents of the frame.
-When using a built-in [aggregate function](#AggregateFunctions) as a
-window function, the function’s argument must be a subquery which refers to
-this alias, for example:
-
-    FROM source AS src
-    SELECT ARRAY_COUNT(DISTINCT (FROM alias SELECT VALUE alias.src.field))
-    OVER alias AS (PARTITION BY … ORDER BY …)
-
-The alias is not necessary when using a [window function](#WindowFunctions),
-or when using a standard SQL aggregate function with the OVER clause.
-
-#### Standard SQL Aggregate Functions with the Window Clause ####
-
-A standard SQL aggregate function with an OVER clause is rewritten by the
-query compiler using a built-in aggregate function over a frame variable.
-For example, the following query with the `sum()` function:
-
-    FROM source AS src
-    SELECT SUM(field)
-    OVER (PARTITION BY … ORDER BY …)
-
-Is rewritten as the following query using the `array_sum()` function:
-
-    FROM source AS src
-    SELECT ARRAY_SUM( (FROM alias SELECT VALUE alias.src.field) )
-    OVER alias AS (PARTITION BY … ORDER BY …)
-
-This is similar to the way that standard SQL aggregate functions are rewritten
-as built-in aggregate functions in the presence of the GROUP BY clause.
-
-### <a id="window-definition">Window Definition</a> ###
-
-    WindowDefinition ::= (WindowPartitionClause)? (WindowOrderClause
-    (WindowFrameClause (WindowFrameExclusion)? )? )?
-
-The **window definition** specifies the partitioning, ordering, and framing for
-window functions.
-
-#### <a id="window-partition-clause">Window Partition Clause</a> ####
-
-    WindowPartitionClause ::= <PARTITION> <BY> Expression ("," Expression)*
-
-The **window partition clause** divides the tuples into partitions using
-one or more expressions.
-
-This clause may be used with any [window function](#WindowFunctions), or any
-[aggregate function](#AggregateFunctions) used as a window function.
-
-This clause is optional.
-If omitted, all tuples are united in a single partition.
-
-#### <a id="window-order-clause">Window Order Clause</a> ####
-
-    WindowOrderClause ::= <ORDER> <BY> OrderingTerm ("," OrderingTerm)*
-
-The **window order clause** determines how tuples are ordered within each
-partition.
-The window function works on tuples in the order specified by this clause.
-
-This clause may be used with any [window function](#WindowFunctions), or any
-[aggregate function](#AggregateFunctions) used as a window function.
-
-This clause is optional for some functions, and required for others.
-Refer to the [Aggregate Functions](#AggregateFunctions) section or the
-[Window Functions](#WindowFunctions) section for details of the syntax of
-individual functions.
-
-If this clause is omitted, all tuples are considered peers, i.e. their order
-is tied.
-When tuples in the window partition are tied, each window function behaves
-differently.
-
-* The `row_number()` function returns a distinct number for each tuple.
-  If tuples are tied, the results may be unpredictable.
-
-* The `rank()`, `dense_rank()`, `percent_rank()`, and `cume_dist()` functions
-  return the same result for each tuple.
-
-* For other functions, if the [window frame](#window-frame-clause) is
-  defined by `ROWS`, the results may be unpredictable.
-  If the window frame is defined by `RANGE` or `GROUPS`, the results are same
-  for each tuple.
-
-This clause may have multiple [ordering terms](#ordering-term).
-To reduce the number of ties, add additional [ordering terms](#ordering-term).
-
-##### NOTE #####
-
-This clause does not guarantee the overall order of the query results.
-To guarantee the order of the final results, use the query ORDER BY clause.
-
-#### <a id="ordering-term">Ordering Term</a> ####
-
-    OrderingTerm ::= Expression ( <ASC> | <DESC> )?
-
-The **ordering term** specifies an ordering expression and collation.
-
-This clause has the same syntax and semantics as the ordering term for queries.
-Refer to the [ORDER BY clause](manual.html#Order_By_clauses) section
-for details.
-
-#### <a id="window-frame-clause">Window Frame Clause</a> ####
-
-    WindowFrameClause ::= ( <ROWS> | <RANGE> | <GROUPS> ) WindowFrameExtent
-
-The **window frame clause** defines the window frame.
-
-This clause can be used with all [aggregate functions](#AggregateFunctions) and
-some [window functions](#WindowFunctions) — refer to the descriptions of
-individual functions for more details.
-
-This clause is allowed only when the [window order
-clause](#window-order-clause) is present.
-
-This clause is optional.
-
-* If this clause is omitted and there is no [window order
-  clause](#window-order-clause), the window frame is the entire partition.
-
-* If this clause is omitted but there is a [window order
-  clause](#window-order-clause), the window frame becomes all tuples
-  in the partition preceding the current tuple and its peers — the
-  same as `RANGE BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW`.
-
-The window frame can be defined in the following ways:
-
-* `ROWS`: Counts the exact number of tuples within the frame.
-  If window ordering doesn’t result in unique ordering, the function may
-  produce unpredictable results.
-  You can add a unique expression or more window ordering expressions to
-  produce unique ordering.
-
-* `RANGE`: Looks for a value offset within the frame.
-  The function produces deterministic results.
-
-* `GROUPS`: Counts all groups of tied rows within the frame.
-  The function produces deterministic results.
-
-##### NOTE #####
-
-If this clause uses `RANGE` with either `Expression PRECEDING` or
-`Expression FOLLOWING`, the [window order clause](#window-order-clause) must
-have only a single ordering term.
-The ordering term expression must evaluate to a number, a date, a time, or a
-datetime.
-If the ordering term expression evaluates to a date, a time, or a datetime, the
-expression in `Expression PRECEDING` or `Expression FOLLOWING` must evaluate to
-a duration.
-
-If these conditions are not met, the window frame will be empty,
-which means the window function will return its default
-value: in most cases this is NULL, except for `strict_count()` or
-`array_count()`, whose default value is 0.
-
-This restriction does not apply when the window frame uses `ROWS` or
-`GROUPS`.
-
-##### TIP #####
-
-The `RANGE` window frame is commonly used to define window frames based
-on date or time.
-
-If you want to use `RANGE` with either `Expression PRECEDING` or `Expression
-FOLLOWING`, and you want to use an ordering expression based on date or time,
-the expression in `Expression PRECEDING` or `Expression FOLLOWING` must use a
-data type that can be added to the ordering expression.
-
-#### <a id="window-frame-extent">Window Frame Extent</a> ####
-
-    WindowFrameExtent ::= ( <UNBOUNDED> <PRECEDING> | <CURRENT> <ROW> |
-    Expression <FOLLOWING> ) | <BETWEEN> ( <UNBOUNDED> <PRECEDING> | <CURRENT>
-    <ROW> | Expression ( <PRECEDING> | <FOLLOWING> ) ) <AND> ( <UNBOUNDED>
-    <FOLLOWING> | <CURRENT> <ROW> | Expression ( <PRECEDING> | <FOLLOWING> ) )
-
-The **window frame extent clause** specifies the start point and end point of
-the window frame.
-The expression before `AND` is the start point and the expression after `AND`
-is the end point.
-If `BETWEEN` is omitted, you can only specify the start point; the end point
-becomes `CURRENT ROW`.
-
-The window frame end point can’t be before the start point.
-If this clause violates this restriction explicitly, an error will result.
-If it violates this restriction implicitly, the window frame will be empty,
-which means the window function will return its default value:
-in most cases this is NULL, except for `strict_count()` or
-`array_count()`, whose default value is 0.
-
-Window frame extents that result in an explicit violation are:
-
-* `BETWEEN CURRENT ROW AND Expression PRECEDING`
-
-* `BETWEEN Expression FOLLOWING AND Expression PRECEDING`
-
-* `BETWEEN Expression FOLLOWING AND CURRENT ROW`
-
-Window frame extents that result in an implicit violation are:
-
-* `BETWEEN UNBOUNDED PRECEDING AND Expression PRECEDING` — if `Expression` is
-  too high, some tuples may generate an empty window frame.
-
-* `BETWEEN Expression PRECEDING AND Expression PRECEDING` — if the second
-  `Expression` is greater than or equal to the first `Expression`,
-  all result sets will generate an empty window frame.
-
-* `BETWEEN Expression FOLLOWING AND Expression FOLLOWING` — if the first
-  `Expression` is greater than or equal to the second `Expression`, all result
-  sets will generate an empty window frame.
-
-* `BETWEEN Expression FOLLOWING AND UNBOUNDED FOLLOWING` — if `Expression` is
-  too high, some tuples may generate an empty window frame.
-
-* If the [window frame exclusion clause](#window-frame-exclusion) is present,
-  any window frame specification may result in empty window frame.
-
-The `Expression` must be a positive constant or an expression that evaluates as
-a positive number.
-For `ROWS` or `GROUPS`, the `Expression` must be an integer.
-
-#### <a id="window-frame-exclusion">Window Frame Exclusion</a> ####
-
-    WindowFrameExclusion ::= <EXCLUDE> ( <CURRENT> <ROW> | <GROUP> | <TIES> |
-    <NO> <OTHERS> )
-
-The **window frame exclusion clause** enables you to exclude specified
-tuples from the window frame.
-
-This clause can be used with all [aggregate functions](#AggregateFunctions) and
-some [window functions](#WindowFunctions) — refer to the descriptions of
-individual functions for more details.
-
-This clause is allowed only when the [window frame
-clause](#window-frame-clause) is present.
-
-This clause is optional.
-If this clause is omitted, the default is no exclusion —
-the same as `EXCLUDE NO OTHERS`.
-
-* `EXCLUDE CURRENT ROW`: If the current tuple is still part of the window
-  frame, it is removed from the window frame.
-
-* `EXCLUDE GROUP`: The current tuple and any peers of the current tuple are
-  removed from the window frame.
-
-* `EXCLUDE TIES`: Any peers of the current tuple, but not the current tuple
-  itself, are removed from the window frame.
-
-* `EXCLUDE NO OTHERS`: No additional tuples are removed from the window frame.
-
-If the current tuple is already removed from the window frame, then it remains
-removed from the window frame.
diff --git a/asterixdb/asterix-doc/src/main/markdown/builtins/9_aggregate_sql.md b/asterixdb/asterix-doc/src/main/markdown/builtins/9_aggregate_sql.md
index b073225..93f6d9a 100644
--- a/asterixdb/asterix-doc/src/main/markdown/builtins/9_aggregate_sql.md
+++ b/asterixdb/asterix-doc/src/main/markdown/builtins/9_aggregate_sql.md
@@ -33,7 +33,7 @@
 Refer to [Aggregation Functions](manual.html#Aggregation_functions) for details.
 
 Aggregate functions may be used as window functions when they are used with an OVER clause.
-Refer to [OVER Clause](#OverClause) for details.
+Refer to [OVER Clauses](manual.html#Over_clauses) for details.
 
 ### array_count ###
  * Syntax:
diff --git a/asterixdb/asterix-doc/src/main/markdown/sqlpp/0_toc.md b/asterixdb/asterix-doc/src/main/markdown/sqlpp/0_toc.md
index c108cc0..1a5a3e6 100644
--- a/asterixdb/asterix-doc/src/main/markdown/sqlpp/0_toc.md
+++ b/asterixdb/asterix-doc/src/main/markdown/sqlpp/0_toc.md
@@ -71,6 +71,11 @@
       * [WITH Clauses](#With_clauses)
       * [LET Clauses](#Let_clauses)
       * [UNION ALL](#Union_all)
+      * [OVER Clauses](#Over_clauses)
+           * [Window Function Call](#Window_function_call)
+           * [Window Function Options](#Window_function_options)
+           * [Window Frame Variable](#Window_frame_variable)
+           * [Window Definition](#Window_definition)
       * [Differences from SQL-92](#Vs_SQL-92)
 * [4. Errors](#Errors)
       * [Syntax Errors](#Syntax_errors)
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 efc2a86..37e7f79 100644
--- a/asterixdb/asterix-doc/src/main/markdown/sqlpp/2_expr.md
+++ b/asterixdb/asterix-doc/src/main/markdown/sqlpp/2_expr.md
@@ -250,7 +250,7 @@
                   | CaseExpression
                   | Constructor
 
-The most basic building block for any expression in the query langauge is PrimaryExpression.
+The most basic building block for any expression in the query language is PrimaryExpression.
 This can be a simple literal (constant) value, a reference to a query variable that is in scope, a parenthesized
 expression, a function call, or a newly constructed instance of the data model (such as a newly constructed object,
 array, or multiset of data model instances).
@@ -386,7 +386,7 @@
 
 ### <a id="Function_call_expressions">Function Call Expressions</a>
 
-    FunctionCallExpression ::= FunctionName "(" ( Expression ( "," Expression )* )? ")"
+    FunctionCallExpression ::= ( FunctionName "(" ( Expression ( "," Expression )* )? ")" ) | WindowFunctionCall
 
 Functions are included in the query language, like most languages, as a way to package useful functionality or to
 componentize complicated or reusable computations.
@@ -394,6 +394,9 @@
 expression with the given parameter bindings; the parameter value bindings can themselves be any expressions in the
 query language.
 
+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 [OVER Clauses](#Over_clauses).
+
 The following example is a (built-in) 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 9f9db63..f4b5f3d 100644
--- a/asterixdb/asterix-doc/src/main/markdown/sqlpp/3_query.md
+++ b/asterixdb/asterix-doc/src/main/markdown/sqlpp/3_query.md
@@ -1661,7 +1661,7 @@
 UNION ALL can be used to combine two input arrays or multisets into one. As in SQL, there is no ordering guarantee
 on the contents of the output stream.
 However, unlike SQL, the query language does not constrain what the data looks like on the input streams; in particular,
-it allows heterogenity on the input and output streams.
+it allows heterogeneity on the input and output streams.
 A type error will be raised if one of the inputs is not a collection.
 The following odd but legal query is an example:
 
@@ -1684,6 +1684,336 @@
     }, " like product-y the plan is amazing"
      ]
 
+## <a id="Over_clauses">OVER Clauses</a> ##
+
+All window functions must have an OVER clause to define the window partitions,
+the order of tuples within those partitions, and the extent of the window frame.
+Some window functions take additional window options, which are specified by
+modifiers before the OVER clause.
+
+The query language has a dedicated set of window functions.
+Aggregate functions can also be used as window functions, when they are used
+with an OVER clause.
+
+### <a id="Window_function_call">Window Function Call</a> ###
+
+    WindowFunctionCall ::= WindowFunctionType "(" WindowFunctionArguments ")"
+    (WindowFunctionOptions)? <OVER> (Variable <AS>)? "(" WindowClause ")"
+
+#### <a id="Window_function_type">Window Function Type</a> ####
+
+    WindowFunctionType ::= AggregateFunctions | WindowFunctions
+
+Refer to the [Aggregate Functions](builtins.html#AggregateFunctions) section
+for a list of aggregate functions.
+
+Refer to the [Window Functions](builtins.html#WindowFunctions) section for a
+list of window functions.
+
+#### <a id="Window_function_arguments">Window Function Arguments</a> ####
+
+    WindowFunctionArguments ::= ( (<DISTINCT>)? Expression |
+    (Expression ("," Expression ("," Expression)? )? )? )
+
+Refer to the [Aggregate Functions](builtins.html#AggregateFunctions) section or
+the [Window Functions](builtins.html#WindowFunctions) section for details of
+the arguments for individual functions.
+
+### <a id="Window_function_options">Window Function Options</a> ###
+
+    WindowFunctionOptions ::= (NthValFrom)? (NullsTreatment)?
+
+Window function options cannot be used with [aggregate
+functions](builtins.html#AggregateFunctions).
+
+Window function options can only be used with some [window
+functions](builtins.html#WindowFunctions), as described below.
+
+#### <a id="Nth_val_from">Nth Val From</a> ####
+
+    NthValFrom ::= <FROM> ( <FIRST> | <LAST> )
+
+The **nth val from** modifier determines whether the computation begins at the
+first or last tuple in the window.
+
+This modifier can only be used with the `nth_value()` function.
+
+This modifier is optional.
+If omitted, the default setting is `FROM FIRST`.
+
+#### <a id="Nulls_treatment">Nulls Treatment</a> ####
+
+    NullsTreatment ::= ( <RESPECT> | <IGNORE> ) <NULLS>
+
+The **nulls treatment** modifier determines whether NULL values are included in
+the computation, or ignored.
+MISSING values are treated the same way as NULL values.
+
+This modifier can only be used with the `first_value()`, `last_value()`,
+`nth_value()`, `lag()`, and `lead()` functions.
+
+This modifier is optional.
+If omitted, the default setting is `RESPECT NULLS`.
+
+### <a id="Window_frame_variable">Window Frame Variable</a> ###
+
+The AS keyword enables you to specify an alias for the window frame contents.
+It introduces a variable which will be bound to the contents of the frame.
+When using a built-in [aggregate function](builtins.html#AggregateFunctions) as
+a window function, the function’s argument must be a subquery which refers to
+this alias, for example:
+
+    FROM source AS src
+    SELECT ARRAY_COUNT(DISTINCT (FROM alias SELECT VALUE alias.src.field))
+    OVER alias AS (PARTITION BY … ORDER BY …)
+
+The alias is not necessary when using a [window function](builtins.html#WindowFunctions),
+or when using a standard SQL aggregate function with the OVER clause.
+
+#### <a id="SQL-92_over_clause">Standard SQL Aggregate Functions with the OVER Clause</a> ####
+
+A standard SQL aggregate function with an OVER clause is rewritten by the
+query compiler using a built-in aggregate function over a frame variable.
+For example, the following query with the `sum()` function:
+
+    FROM source AS src
+    SELECT SUM(field)
+    OVER (PARTITION BY … ORDER BY …)
+
+Is rewritten as the following query using the `array_sum()` function:
+
+    FROM source AS src
+    SELECT ARRAY_SUM( (FROM alias SELECT VALUE alias.src.field) )
+    OVER alias AS (PARTITION BY … ORDER BY …)
+
+This is similar to the way that standard SQL aggregate functions are rewritten
+as built-in aggregate functions in the presence of the GROUP BY clause.
+
+### <a id="Window_definition">Window Definition</a> ###
+
+    WindowDefinition ::= (WindowPartitionClause)? (WindowOrderClause
+    (WindowFrameClause (WindowFrameExclusion)? )? )?
+
+The **window definition** specifies the partitioning, ordering, and framing for
+window functions.
+
+#### <a id="Window_partition_clause">Window Partition Clause</a> ####
+
+    WindowPartitionClause ::= <PARTITION> <BY> Expression ("," Expression)*
+
+The **window partition clause** divides the tuples into partitions using
+one or more expressions.
+
+This clause may be used with any [window function](builtins.html#WindowFunctions),
+or any [aggregate function](builtins.html#AggregateFunctions) used as a window
+function.
+
+This clause is optional.
+If omitted, all tuples are united in a single partition.
+
+#### <a id="Window_order_clause">Window Order Clause</a> ####
+
+    WindowOrderClause ::= <ORDER> <BY> OrderingTerm ("," OrderingTerm)*
+
+The **window order clause** determines how tuples are ordered within each
+partition.
+The window function works on tuples in the order specified by this clause.
+
+This clause may be used with any [window function](builtins.html#WindowFunctions),
+or any [aggregate function](builtins.html#AggregateFunctions) used as a window
+function.
+
+This clause is optional for some functions, and required for others.
+Refer to the [Aggregate Functions](builtins.html#AggregateFunctions) section or
+the [Window Functions](builtins.html#WindowFunctions) section for details of
+the syntax of individual functions.
+
+If this clause is omitted, all tuples are considered peers, i.e. their order
+is tied.
+When tuples in the window partition are tied, each window function behaves
+differently.
+
+* The `row_number()` function returns a distinct number for each tuple.
+  If tuples are tied, the results may be unpredictable.
+
+* The `rank()`, `dense_rank()`, `percent_rank()`, and `cume_dist()` functions
+  return the same result for each tuple.
+
+* For other functions, if the [window frame](#Window_frame_clause) is
+  defined by `ROWS`, the results may be unpredictable.
+  If the window frame is defined by `RANGE` or `GROUPS`, the results are same
+  for each tuple.
+
+This clause may have multiple [ordering terms](#Ordering_term).
+To reduce the number of ties, add additional [ordering terms](#Ordering_term).
+
+##### Note #####
+
+This clause does not guarantee the overall order of the query results.
+To guarantee the order of the final results, use the query ORDER BY clause.
+
+#### <a id="Ordering_term">Ordering Term</a> ####
+
+    OrderingTerm ::= Expression ( <ASC> | <DESC> )?
+
+The **ordering term** specifies an ordering expression and collation.
+
+This clause has the same syntax and semantics as the ordering term for queries.
+Refer to the [ORDER BY Clauses](#Order_By_clauses) section for details.
+
+#### <a id="Window_frame_clause">Window Frame Clause</a> ####
+
+    WindowFrameClause ::= ( <ROWS> | <RANGE> | <GROUPS> ) WindowFrameExtent
+
+The **window frame clause** defines the window frame.
+
+This clause can be used with all
+[aggregate functions](builtins.html#AggregateFunctions)
+and some [window functions](builtins.html#WindowFunctions) —
+refer to the descriptions of individual functions for more details.
+
+This clause is allowed only when the [window order
+clause](#Window_order_clause) is present.
+
+This clause is optional.
+
+* If this clause is omitted and there is no [window order
+  clause](#Window_order_clause), the window frame is the entire partition.
+
+* If this clause is omitted but there is a [window order
+  clause](#Window_order_clause), the window frame becomes all tuples
+  in the partition preceding the current tuple and its peers — the
+  same as `RANGE BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW`.
+
+The window frame can be defined in the following ways:
+
+* `ROWS`: Counts the exact number of tuples within the frame.
+  If window ordering doesn’t result in unique ordering, the function may
+  produce unpredictable results.
+  You can add a unique expression or more window ordering expressions to
+  produce unique ordering.
+
+* `RANGE`: Looks for a value offset within the frame.
+  The function produces deterministic results.
+
+* `GROUPS`: Counts all groups of tied rows within the frame.
+  The function produces deterministic results.
+
+##### Note #####
+
+If this clause uses `RANGE` with either `Expression PRECEDING` or
+`Expression FOLLOWING`, the [window order clause](#Window_order_clause) must
+have only a single ordering term.
+The ordering term expression must evaluate to a number, a date, a time, or a
+datetime.
+If the ordering term expression evaluates to a date, a time, or a datetime, the
+expression in `Expression PRECEDING` or `Expression FOLLOWING` must evaluate to
+a duration.
+
+If these conditions are not met, the window frame will be empty,
+which means the window function will return its default
+value: in most cases this is NULL, except for `strict_count()` or
+`array_count()`, whose default value is 0.
+
+This restriction does not apply when the window frame uses `ROWS` or
+`GROUPS`.
+
+##### Tip #####
+
+The `RANGE` window frame is commonly used to define window frames based
+on date or time.
+
+If you want to use `RANGE` with either `Expression PRECEDING` or `Expression
+FOLLOWING`, and you want to use an ordering expression based on date or time,
+the expression in `Expression PRECEDING` or `Expression FOLLOWING` must use a
+data type that can be added to the ordering expression.
+
+#### <a id="Window_frame_extent">Window Frame Extent</a> ####
+
+    WindowFrameExtent ::= ( <UNBOUNDED> <PRECEDING> | <CURRENT> <ROW> |
+    Expression <FOLLOWING> ) | <BETWEEN> ( <UNBOUNDED> <PRECEDING> | <CURRENT>
+    <ROW> | Expression ( <PRECEDING> | <FOLLOWING> ) ) <AND> ( <UNBOUNDED>
+    <FOLLOWING> | <CURRENT> <ROW> | Expression ( <PRECEDING> | <FOLLOWING> ) )
+
+The **window frame extent clause** specifies the start point and end point of
+the window frame.
+The expression before `AND` is the start point and the expression after `AND`
+is the end point.
+If `BETWEEN` is omitted, you can only specify the start point; the end point
+becomes `CURRENT ROW`.
+
+The window frame end point can’t be before the start point.
+If this clause violates this restriction explicitly, an error will result.
+If it violates this restriction implicitly, the window frame will be empty,
+which means the window function will return its default value:
+in most cases this is NULL, except for `strict_count()` or
+`array_count()`, whose default value is 0.
+
+Window frame extents that result in an explicit violation are:
+
+* `BETWEEN CURRENT ROW AND Expression PRECEDING`
+
+* `BETWEEN Expression FOLLOWING AND Expression PRECEDING`
+
+* `BETWEEN Expression FOLLOWING AND CURRENT ROW`
+
+Window frame extents that result in an implicit violation are:
+
+* `BETWEEN UNBOUNDED PRECEDING AND Expression PRECEDING` — if `Expression` is
+  too high, some tuples may generate an empty window frame.
+
+* `BETWEEN Expression PRECEDING AND Expression PRECEDING` — if the second
+  `Expression` is greater than or equal to the first `Expression`,
+  all result sets will generate an empty window frame.
+
+* `BETWEEN Expression FOLLOWING AND Expression FOLLOWING` — if the first
+  `Expression` is greater than or equal to the second `Expression`, all result
+  sets will generate an empty window frame.
+
+* `BETWEEN Expression FOLLOWING AND UNBOUNDED FOLLOWING` — if `Expression` is
+  too high, some tuples may generate an empty window frame.
+
+* If the [window frame exclusion clause](#Window_frame_exclusion) is present,
+  any window frame specification may result in empty window frame.
+
+The `Expression` must be a positive constant or an expression that evaluates as
+a positive number.
+For `ROWS` or `GROUPS`, the `Expression` must be an integer.
+
+#### <a id="Window_frame_exclusion">Window Frame Exclusion</a> ####
+
+    WindowFrameExclusion ::= <EXCLUDE> ( <CURRENT> <ROW> | <GROUP> | <TIES> |
+    <NO> <OTHERS> )
+
+The **window frame exclusion clause** enables you to exclude specified
+tuples from the window frame.
+
+This clause can be used with all
+[aggregate functions](builtins.html#AggregateFunctions)
+and some [window functions](builtins.html#WindowFunctions) —
+refer to the descriptions of individual functions for more details.
+
+This clause is allowed only when the [window frame
+clause](#Window_frame_clause) is present.
+
+This clause is optional.
+If this clause is omitted, the default is no exclusion —
+the same as `EXCLUDE NO OTHERS`.
+
+* `EXCLUDE CURRENT ROW`: If the current tuple is still part of the window
+  frame, it is removed from the window frame.
+
+* `EXCLUDE GROUP`: The current tuple and any peers of the current tuple are
+  removed from the window frame.
+
+* `EXCLUDE TIES`: Any peers of the current tuple, but not the current tuple
+  itself, are removed from the window frame.
+
+* `EXCLUDE NO OTHERS`: No additional tuples are removed from the window frame.
+
+If the current tuple is already removed from the window frame, then it remains
+removed from the window frame.
+
 ## <a id="Subqueries">Subqueries</a>
 In the query language, an arbitrary subquery can appear anywhere that an expression can appear.
 Unlike SQL-92, as was just alluded to, the subqueries in a SELECT list or a boolean predicate need

-- 
To view, visit https://asterix-gerrit.ics.uci.edu/3464
To unsubscribe, visit https://asterix-gerrit.ics.uci.edu/settings

Gerrit-Project: asterixdb
Gerrit-Branch: master
Gerrit-MessageType: merged
Gerrit-Change-Id: I683d024c56fcc55d67e1f87eec5494781bbcdede
Gerrit-Change-Number: 3464
Gerrit-PatchSet: 2
Gerrit-Owner: Simon Dew <Simon.Dew@couchbase.com>
Gerrit-Reviewer: Anon. E. Moose (1000171)
Gerrit-Reviewer: Dmitry Lychagin <dmitry.lychagin@couchbase.com>
Gerrit-Reviewer: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Gerrit-Reviewer: Simon Dew <Simon.Dew@couchbase.com>
Gerrit-Reviewer: Till Westmann <tillw@apache.org>

Mime
View raw message