trinodb / trino

Official repository of Trino, the distributed SQL query engine for big data, formerly known as PrestoSQL (https://trino.io)
https://trino.io
Apache License 2.0
10.49k stars 3.02k forks source link

Window ordering is not enforced for `ntile` and ranking window functions #24163

Open kasiafi opened 3 days ago

kasiafi commented 3 days ago

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:

I suggest that we:

or do not enforce window ordering at all, but instead document explicitly the unordered behavior.