You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
According to SQL specification ISO/IEC 9075-2:2023(E) 9.23 Evaluationandtransformationof<windowfunction>, p. 665:
5) If <ntile function>, <lead or lag function>, <rank function type> or ROW_NUMBER is specified, then:
a) If <ntile function>, <lead or lag function>, or <rank function type> is specified, then the window ordering clause WOC of WDX shall be present.
We check for the window ordering clause only for the lead() and lag() functions.
Here's how the remaining functions behave without window ordering:
rank() and dense_rank() return 1 for all rows. This is expected and kind of intuitive, as in the absence of ordering, all rows are peers.
percent_rank() returns 0.0 for every row, which is consistent with the function's semantics where all rows are peers.
cume_dist() returns 1.0 for every row, which is consistent with the function's semantics where all rows are peers.
ntile() assigns buckets to rows in their input order. It might be useful, but the name ntile is not relevant.
According to SQL specification
ISO/IEC 9075-2:2023(E) 9.23 Evaluationandtransformationof<windowfunction>
, p. 665:We check for the window ordering clause only for the
lead()
andlag()
functions.Here's how the remaining functions behave without window ordering:
rank()
anddense_rank()
return1
for all rows. This is expected and kind of intuitive, as in the absence of ordering, all rows are peers.percent_rank()
returns0.0
for every row, which is consistent with the function's semantics where all rows are peers.cume_dist()
returns1.0
for every row, which is consistent with the function's semantics where all rows are peers.ntile()
assigns buckets to rows in their input order. It might be useful, but the namentile
is not relevant.I suggest that we:
ntile
, and add another ntile-like function for random bucketingor do not enforce window ordering at all, but instead document explicitly the unordered behavior.
The text was updated successfully, but these errors were encountered: