Window ordering when no ordering clause is specified
See original GitHub issueConsider following query:
with test (a, b, c) as (
(VALUES (0, 5, 50),
(0, 3, 30),
(0, 4, 40),
(0, 1, 10),
(1, 8, 80),
(1, 7, 70)
)
),
test_ordered AS (
SELECT * FROM test ORDER BY a, b
)
SELECT
a,
array_agg(c) OVER(PARTITION BY a) sequence
FROM test_ordered
Can I assume that the ordering for window function be the same as the one in output of test_ordered
when window ordering cluase for window function is not specified?
So the expected output always be:
0 | [10, 30, 40, 50] 0 | [10, 30, 40, 50] 0 | [10, 30, 40, 50] 0 | [10, 30, 40, 50] 1 | [70, 80] 1 | [70, 80]
This what I found in SQL spec:
If WD has no window ordering clause, then the window ordering is implementation-dependent, and all rows are peers. Although the window ordering of peer rows within a window partition is implementation-dependent, the window ordering shall be the same for all window structure descriptors that are order-equivalent. It shall also be the same for any pair of windows W1 and W2 such that W1 is the ordering window for W2.
However I didn’t find any details in presto documentation.
Edit: I refer to Athena (Presto 0.172 if I’m not wrong)
Issue Analytics
- State:
- Created 4 years ago
- Comments:5 (3 by maintainers)
Top GitHub Comments
If the order isn’t specified, Presto doesn’t guarantee that it will be in any particular order (and, since it’s not semantically required by your query presto could remove the initial order by entirely: https://github.com/prestodb/presto/issues/7613)
@rschlussel Sure, thank you for the answer, it was very helpful!