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

[feature request] named window expressions? #624

Closed
yitao-li opened this issue Mar 25, 2021 · 1 comment · Fixed by #631
Closed

[feature request] named window expressions? #624

yitao-li opened this issue Mar 25, 2021 · 1 comment · Fixed by #631

Comments

@yitao-li
Copy link
Contributor

yitao-li commented Mar 25, 2021

Is there a way in dbplyr to generate SQL of the form

SELECT
  SUM(`col1`) OVER `wnd` AS `s1`,
  SUM(`col2`) OVER `wnd` AS `s2`,
  SUM(`col3`) OVER `wnd` AS `s3`
FROM `my_table`
  WINDOW `wnd` AS (PARTITION BY `col4` ORDER BY `col5`)

?

(i.e., avoid spelling out the same window-spec repeatedly within the same query, and refer to it by a name instead) ?

The benefit of having this is the generated query would be shorter and easier to debug (as it's immediately clear that the same window spec is applied to multiple aggregations).

@hadley
Copy link
Member

hadley commented Apr 1, 2021

Not currently, and I suspect it wouldn't be worth the effort to implement it because it involving somehow hoisting data about individual expressions up to the query level. Not impossible, but I'd need to spend a decent amount of time thinking about it, and investigating support for WINDOW across databases.

@hadley hadley closed this as completed Apr 1, 2021
@mgirlich mgirlich mentioned this issue Apr 6, 2021
13 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants