You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@calcite.apache.org by "Julian Hyde (Jira)" <ji...@apache.org> on 2024/08/20 21:06:00 UTC
[jira] [Comment Edited] (CALCITE-5883) Calcite ignores window frames when there is no ORDER BY clause
[ https://issues.apache.org/jira/browse/CALCITE-5883?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17875289#comment-17875289 ]
Julian Hyde edited comment on CALCITE-5883 at 8/20/24 9:05 PM:
---------------------------------------------------------------
I have changed my mind about this. Consider the query
{code:sql}
SELECT sum(x) OVER (ROWS BETWEEN 3 PRECEDING AND 2 PRECEDING)
FROM t {code}
Since there is no {{ORDER BY}} clause, it is nondeterministic. (But queries with an {{ORDER BY}} clause are nondeterministic also, if the key is not unique.) Although it is nondeterministic, we know that it evaluates over a window of one row (except for the first 3 rows, where the window is not yet full). So that's what we should do.
CALCITE-6538 deals with the special case of {{CURRENT ROW}}. Applying the above logic, {{SUM(x) OVER (ROWS CURRENT ROW)}} should always return x. {{ROWS CURRENT ROW}} is deterministic, even without an {{ORDER BY}}.
In summary, I think we should keep the bounds if the window is {{ROWS}}, even if there is no {{ORDER BY}}.
was (Author: julianhyde):
I have changed my mind about this. Consider the query
{code:sql}
SELECT sum(x) OVER (ROWS BETWEEN 3 PRECEDING AND 2 PRECEDING)
FROM t {code}
Since there is no {{ORDER BY}} clause, it is nondeterministic. (But queries with an {{ORDER BY}} clause are nondeterministic also, if the key is not unique.) Although it is nondeterministic, we know that it evaluates over a window of one row (except for the first 3 rows, where the window is not yet full).
In summary, I think we should keep the bounds if the window is {{ROWS}}, even if there is no {{ORDER BY}}.
> Calcite ignores window frames when there is no ORDER BY clause
> --------------------------------------------------------------
>
> Key: CALCITE-5883
> URL: https://issues.apache.org/jira/browse/CALCITE-5883
> Project: Calcite
> Issue Type: Bug
> Affects Versions: 1.35.0
> Reporter: Itiel Sadeh
> Priority: Major
>
> When specifying window frame without an ORDER BY clause, Calcite will ignore it and will generate the frame UNBOUNDED PRECEDING to UNBOUNDED FOLLOWING. e.g, calcite will translate
> {code:java}
> SELECT sum(x) over(partition by y ROWS between CURRENT ROW and UNBOUNDED FOLLOWING) from t
> {code}
> into
> {code:java}
> SELECT sum(x) over(partition by y RANGE between UNBOUNDED FOLLOWING and UNBOUNDED FOLLOWING) from t
> {code}
> There is a comment in the offending code (SqlToRelConverter.java:2207) which states that
> ??"without ORDER BY, there must be no bracketing"?? . I've tried to find a specification like that in the SQL 2003 standard, but didn't find anything to that effect.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)