Repository: tajo Updated Branches: refs/heads/master 33b8893fe -> 8db6928a4
TAJO-1641: Add window function documentation. Closes #738 Project: http://git-wip-us.apache.org/repos/asf/tajo/repo Commit: http://git-wip-us.apache.org/repos/asf/tajo/commit/8db6928a Tree: http://git-wip-us.apache.org/repos/asf/tajo/tree/8db6928a Diff: http://git-wip-us.apache.org/repos/asf/tajo/diff/8db6928a Branch: refs/heads/master Commit: 8db6928a47a044f83c30027a2749906d2797a030 Parents: 33b8893 Author: Jihoon Son <[email protected]> Authored: Mon Sep 7 20:12:31 2015 +0900 Committer: Jihoon Son <[email protected]> Committed: Mon Sep 7 20:12:31 2015 +0900 ---------------------------------------------------------------------- CHANGES | 2 + .../main/sphinx/sql_language/sql_expression.rst | 42 ++++++++++++++++++-- 2 files changed, 40 insertions(+), 4 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/tajo/blob/8db6928a/CHANGES ---------------------------------------------------------------------- diff --git a/CHANGES b/CHANGES index 38897bb..6ee478b 100644 --- a/CHANGES +++ b/CHANGES @@ -564,6 +564,8 @@ Release 0.11.0 - unreleased SUB TASKS + TAJO-1641: Add window function documentation. (jihoon) + TAJO-1749: Refine JDBC exceptions to better handle exceptional cases. (hyunsik) http://git-wip-us.apache.org/repos/asf/tajo/blob/8db6928a/tajo-docs/src/main/sphinx/sql_language/sql_expression.rst ---------------------------------------------------------------------- diff --git a/tajo-docs/src/main/sphinx/sql_language/sql_expression.rst b/tajo-docs/src/main/sphinx/sql_language/sql_expression.rst index 4358e3d..41eed3e 100644 --- a/tajo-docs/src/main/sphinx/sql_language/sql_expression.rst +++ b/tajo-docs/src/main/sphinx/sql_language/sql_expression.rst @@ -16,10 +16,10 @@ A type cast converts a specified-typed data to another-typed data. Tajo has two CAST ( expression AS type ) expression::type -In addition, several functions are provided for type conversion. Please refer to `:doc:data_type_func_and_operators` and `:doc:datetime_func_and_operators`. +In addition, several functions are provided for type conversion. Please refer to :doc:`../functions/data_type_func_and_operators` and :doc:`../functions/datetime_func_and_operators`. ------------------------- -String Constants +String Literals ------------------------- A string constant is an arbitrary sequence of characters bounded by single quotes (``'``): @@ -29,7 +29,7 @@ A string constant is an arbitrary sequence of characters bounded by single quote 'tajo' ------------------------- -Function Call +Function Calls ------------------------- The syntax for a function call consists of the name of a function and its argument list enclosed in parentheses: @@ -38,4 +38,38 @@ The syntax for a function call consists of the name of a function and its argume function_name ([expression [, expression ... ]] ) -For more information about functions, please refer to `:doc:functions`. \ No newline at end of file +For more information about functions, please refer to :doc:`../functions`. + +------------------------- +Window Function Calls +------------------------- + +A window function call performs aggregate operation across the ``window`` which is a set of rows that are related to the current row. An window function has the following syntax. + +.. code-block:: sql + + function_name OVER ( window_definition ) + +where *function_name* is the name of aggregation function. Any aggregation function or window function can be used. For built-in aggregation functions and window functions, please refer to :doc:`../functions/agg_func` and :doc:`../functions/window_func`. + +*window_definition* has the following syntax. + +.. code-block:: sql + + [ PARTITION BY expression [, ...] ] + [ ORDER BY expression [ ASC | DESC ] [ NULLS { FIRST | LAST } ] [, ...] ] + +In the above syntax, *expression* can be any expression except window function call itself. +*PARTITION BY* and *ORDER BY* lists have the same syntax and semantics as *GROUP BY* and *ORDER BY* clauses. +That is, *PARTITION BY* list describes how the output result will be partitioned like *GROUP BY* clause creates multiple partitions according to the value of its expression. +With *ORDER BY* list, result values are sorted in each partition. + +Here are some examples. + +.. code-block:: sql + + select l_orderkey, count(*) as cnt, row_number() over (order by count(*) desc) row_num from lineitem group by l_orderkey order by l_orderkey; + + select o_custkey, o_orderstatus, sum(o_totalprice) over (partition by o_custkey) as price from orders; + + select l_linenumber, l_tax, sum(l_quantity) over (partition by l_linenumber order by l_tax desc) as quantity, avg(l_extendedprice) over (partition by l_shipdate) from lineitem order by l_tax; \ No newline at end of file
