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

Vladimir Sitnikov commented on CALCITE-806:
-------------------------------------------

I don't like discussing the spec, however it looks like we don't have a choice.

{quote}Does that mean that it is illegal to use ROW_NUMBER with any other kind 
of bound?{quote}

This is exactly how I read the following in the spec:
{quote}
If <rank function type> or ROW_NUMBER is specified, then:
b) The window framing of WDX shall not be present.{quote}

In other words, all rank functions+row_number cannot have framing.

I believe we have a validation exactly for this reason:
{{RankWithFrame=ROW/RANGE not allowed with RANK or DENSE_RANK functions}}
Well, it makes sense adding ROW_NUMBER there as well (or parametrize the error 
message with actual name of the function).

Ok, we continue:
{quote}{{ROW_NUMBER() OVER WNS}} is equivalent to the <window function>: 
{{COUNT \(*) OVER (WNS1 ROWS UNBOUNDED PRECEDING)}}{quote}

I read this as follows: whenever you see {{ROW_NUMBER() OVER WNS}}, you take 
window specification (remember, it does not contain framing), overlay it with 
{{ROWS UNBOUNDED PRECEDING}}, and replace {{ROW_NUMBER}} with {{COUNT\(*)}}.

PostgreSQL just silently ignores {{ROWS BETWEEN 3 PRECEDING AND 2 FOLLOWING}} 
in row_number/rank/dense_rank.
Oracle does not allow framing for rank/row_number.

> ROW_NUMBER should emit distinct values
> --------------------------------------
>
>                 Key: CALCITE-806
>                 URL: https://issues.apache.org/jira/browse/CALCITE-806
>             Project: Calcite
>          Issue Type: Bug
>            Reporter: Julian Hyde
>            Assignee: Julian Hyde
>             Fix For: next
>
>
> ROW_NUMBER should emit distinct values even for rows that have identical sort 
> keys, or if there is no sort key. (This is distinct from RANK and DENSE_RANK, 
> which emit the same value for rows with the same sort key.)



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to