Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Settings.renderImplicitWindowRange handling different default window RANGE clause defaults #11851

Closed
5 tasks done
lukaseder opened this issue May 6, 2021 · 1 comment
Closed
5 tasks done

Comments

@lukaseder
Copy link
Member

lukaseder commented May 6, 2021

In Teradata, the default RANGE clause (or rather, ROWS clause, because RANGE isn't supported) is always ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING, irrespective of the presence of an ORDER BY clause:

drop table t;
create table t (a int);
insert into t values (1);
insert into t values (2);
insert into t values (3);
insert into t values (4);

select 
  sum(a) over (order by a),
  sum(a) over (order by a rows between unbounded preceding and current row)
from t

The result being:

|Group Sum(a)|Cumulative Sum(a)|
|------------|-----------------|
|10          |1                |
|10          |3                |
|10          |6                |
|10          |10               |

So, ORDER BY has no effect on aggregate window functions, if not accompanied by a ROWS clause. We might want to offer tooling to standardise this behaviour.

  • OFF Don't generate anything extra (default, current behaviour, opt out option for this improvement)
  • RANGE_UNBOUNDED_PRECEDING Emulate standard behaviour
  • RANGE_ALL Emulate Teradata behaviour
  • ROWS_UNBOUNDED_PRECEDING Emulate standard behaviour (but use ROWS instead of RANGE)
  • ROWS_ALL Emulate Teradata behaviour (but use ROWS instead of RANGE)

The five flags will allow for all desirable configurations:

  • "Emulate standard behaviour" is great when an application is written with jOOQ, and now Teradata support is added to the application
  • "Emulate Teradata behaviour" is useful when using the parser to migrate from Teradata to something else.
@lukaseder lukaseder added this to the Version 3.15.0 milestone May 6, 2021
@lukaseder lukaseder added this to To do in 3.15 Other improvements via automation May 6, 2021
@lukaseder lukaseder removed this from To do in 3.15 Other improvements May 6, 2021
@lukaseder lukaseder added this to To do in 3.15 SQL Transformations via automation May 6, 2021
@lukaseder lukaseder changed the title Add a flag handling different default window RANGE clause defaults Add Settings.renderImplicitWindowRange handling different default window RANGE clause defaults May 6, 2021
3.15 SQL Transformations automation moved this from To do to Done May 6, 2021
@lukaseder
Copy link
Member Author

Commit will be included with this issue here: #11850

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Development

No branches or pull requests

1 participant