Skip to content

Commit

Permalink
TEIID-5447 TEIID-5442 updating docs for new analytic functions
Browse files Browse the repository at this point in the history
  • Loading branch information
shawkins committed Aug 29, 2018
1 parent 33d8e1e commit 0434a82
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 7 deletions.
16 changes: 16 additions & 0 deletions dev/Translator_Capabilities.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,22 @@ The following table lists the capabilities that can be specified in the `Executi
|ElementaryOlapOperations
|Translator supports aggregate conditions.

|WindowFunctionCumeDist
|
|Translator supports CUME_DIST window function. Defaults to the support value for ElementaryOlapOperations

|WindowFunctionPercentDist
|
|Translator supports PERCENT_DIST window function. Defaults to the support value for ElementaryOlapOperations

|WindowFunctionNtile
|
|Translator supports NTILE window function. Defaults to the support value for ElementaryOlapOperations

|WindowFunctionNthValue
|
|Translator supports NTH_VALUE window function. Defaults to the support value for ElementaryOlapOperations

|OnlyFormatLiterals
|function support for a parse/format function and an implementation of the supportsFormatLiteral method.
|Translator supports only literal format patterns that must be validated by the supportsFormatLiteral method.
Expand Down
8 changes: 7 additions & 1 deletion reference/BNF_for_SQL_Grammar.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,9 @@
|[[token_CROSS]]_CROSS_
|<<crossJoin,cross join>>

|[[token_CUME_DIST]]_CUME_DIST_
|<<analyticAggregateSymbol,analytic aggregate function>>

|[[token_CURRENT_DATE]]_CURRENT_DATE_
|<<function,function>>

Expand Down Expand Up @@ -365,6 +368,9 @@
|[[token_PARTITION]]_PARTITION_
|<<windowSpecification,window specification>>

|[[token_PERCENT_RANK]]_PERCENT_RANK_
|<<analyticAggregateSymbol,analytic aggregate function>>

|[[token_PRIMARY]]_PRIMARY_
|<<createTempTable,create temporary table>>, <<inlineConstraint,inline constraint>>, <<primaryKey,primary key>>

Expand Down Expand Up @@ -2891,7 +2897,7 @@ COUNT(*)

=== [[analyticAggregateSymbol]]_<<usage_analyticAggregateSymbol, analytic aggregate function>>_ ::=

* ( <<token_ROW_NUMBER,ROW_NUMBER>> | <<token_RANK,RANK>> | <<token_DENSE_RANK,DENSE_RANK>> ) <<<token_LPAREN,lparen>>> <<<token_RPAREN,rparen>>>
* ( <<token_ROW_NUMBER,ROW_NUMBER>> | <<token_RANK,RANK>> | <<token_DENSE_RANK,DENSE_RANK>> | <<token_PERCENT_RANK,PERCENT_RANK>> | <<token_CUME_DIST,CUME_DIST>> ) <<<token_LPAREN,lparen>>> <<<token_RPAREN,rparen>>>


An analytic aggregate function.
Expand Down
18 changes: 12 additions & 6 deletions reference/Expressions.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -211,17 +211,16 @@ Usage:

[source,sql]
----
aggregate|ranking OVER ([PARTITION BY ...]] [ORDER BY ...])
aggregate|analytical OVER ([PARTITION BY ...]] [ORDER BY ...])
----

aggregate can be any link:Expressions.adoc#_aggregate_functions[Aggregate Functions]. Ranking can be one of ROW_NUMBER(), RANK(), DENSE_RANK().
aggregate can be any link:Expressions.adoc#_aggregate_functions[Aggregate Functions]. Keywords exist for the analytical ranking functions which can be one of ROW_NUMBER(), RANK(), DENSE_RANK(), PERCENT_RANK(), CUME_DIST().

Syntax Rules:

* Window functions can only appear in the SELECT and ORDER BY clauses of a query expression.
* Window functions cannot be nested in one another.
* Partitioning and order by expressions cannot contain subqueries or outer references.
* The ranking (ROW_NUMBER, RANK, DENSE_RANK) functions require the use of the window specification ORDER BY clause.
* An XMLAGG or JSONARRAY_AGG ORDER BY clause cannot be used when windowed.
* The window specification ORDER BY clause cannot reference alias names or use positional ordering.
* Windowed aggregates may not use DISTINCT if the window specification is ordered.
Expand All @@ -231,18 +230,25 @@ Syntax Rules:

Ranking Functions:

* ROW_NUMBER() – functional the same as COUNT(*) with the same window specification. Assigns a number to each row in a partition starting at 1.
* RANK() – Assigns a number to each unique ordering value within each partition starting at 1, such that the next rank is equal to the count of prior rows.
* DENSE_RANK() – Assigns a number to each unique ordering value within each partition starting at 1, such that the next rank is sequential.
* PERCENT_RANK() – Computed as (RANK - 1) / ( RC - 1) where RC is the total row count of the partition.
* CUME_DIST() – Computed as the PR / RC where PR is the rank of the row including peers and RC is the total row count of the partition.

All values are integers - an exception will be thrown if a larger value is needed.

Value Functions:

* FIRST_VALUE(val) – Return the first value in the window with the given ordering
* LAST_NUMBER(val) – Return the last observed value in the window with the given ordering
* FIRST_VALUE(val) – Return the first value in the window frame with the given ordering
* LAST_VALUE(val) – Return the last observed value in the window frame with the given ordering
* LEAD(val [, offset [, default]]) - Access the ordered value in the window that is offset rows ahead of the current row. If there is no such row, then the default value will be returned. If not specified the offset is 1 and the default is null.
* LAG(val [, offset [, default]]) - Access the ordered value in the window that is offset rows behind of the current row. If there is no such row, then the default value will be returned. If not specified the offset is 1 and the default is null.
* NTH_VALUE(val, n) - Returns the nth val in window frame. The index must be greater than 0. If no such value exists, then null is returned.

Row Value Functions:

* ROW_NUMBER() – Sequentially assigns a number to each row in a partition starting at 1.
* NTILE(n) – Divides the partition into n tiles that differ in size by at most 1. Larger tiles will be created sequenctially starting at the first. n must be greater than 0.

== Processing

Expand Down

0 comments on commit 0434a82

Please sign in to comment.