[ 
https://issues.apache.org/jira/browse/CALCITE-2224?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16671980#comment-16671980
 ] 

Julian Hyde commented on CALCITE-2224:
--------------------------------------

Sorry I missed this. Thanks for this contribution - it is a very useful 
extension to Calcite's SQL. It's a large PR, so of course we want to complete 
it in a timely manner, to prevent conflicts. I marked it to fix in 1.18 so that 
we don't forget it.

I briefly reviewed and the changes look good:
* I'm glad you have tests for the parser and sql-to-rel converter. Can you also 
add validator tests (SqlValidatorTest.java).
* Also add some tests (both sql-to-rel and .iq) where WITHIN GROUP appears on 
top of a join.
* Please deprecate the two {{RelBuilder.aggregateCall}} methods that take a 
filter but not orderKeys. Also move the {{orderKeys}} argument earlier - it 
should be after {{filter}} and before {{alias}}, so that {{operands}} continues 
to be last. ({{operands}} has to be last because it is var-args.)
* Update algebra.md due to the changes to RelBuilder

Let me know when it's ready to review again.

> WITHIN GROUP clause for aggregate functions
> -------------------------------------------
>
>                 Key: CALCITE-2224
>                 URL: https://issues.apache.org/jira/browse/CALCITE-2224
>             Project: Calcite
>          Issue Type: Bug
>            Reporter: Julian Hyde
>            Assignee: Julian Hyde
>            Priority: Major
>             Fix For: 1.18.0
>
>
> The {{WITHIN GROUP}} clause lets aggregate functions operate on a sorted list 
> of rows, rather than the usual unsorted collection. Order only matters for a 
> few aggregate functions, but we should allow it for all.
> Other analytic functions where {{WITHIN GROUP}} would have an effect: 
> {{RANK}}, {{PERCENT_RANK}}, {{FIRST_VALUE}}, {{LAST_VALUE}}, 
> {{PERCENTILE_CONT}}, {{PERCENTILE_DISC}}.
> {{LISTAGG(value [, separator])}} is an [Oracle 
> function|https://docs.oracle.com/cloud/latest/db112/SQLRF/functions089.htm#SQLRF30030]
>  that concatenates strings. E.g.
> {code:java}
> SELECT LISTAGG(last_name, '; ')
>          WITHIN GROUP (ORDER BY hire_date, last_name)
>   FROM Emp
> GROUP BY deptno{code}
> {{STRING_AGG(value [, separator])}} is a [Microsoft SQL Server function|] 
> that does something similar.
> {{GROUP_CONCAT(value [, separator] [ORDER BY expr [, expr]...)}} is the 
> [MySQL|https://dev.mysql.com/doc/refman/5.7/en/group-by-functions.html#function_group-concat]
>  equivalent to {{LISTAGG}}. Note the optional {{ORDER BY}} clause within the 
> parentheses.
> {{COLLECT(value)}} is a SQL standard aggregate function that creates 
> multisets. Oracle added a non-standard {{ORDER BY}} clause within the 
> parentheses.
> In my opinion, {{WITHIN GROUP}} should always be optional. {{LISTAGG}} 
> without {{WITHIN GROUP}} would produce non-deterministic output (which is 
> OK); other aggregate functions such as {{MIN}} and {{SUM}} would just ignore 
> {{WITHIN GROUP}}.



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to