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

feat: allow window functions in groupby by adding with statement #260

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

frtennis1
Copy link
Contributor

Closes #259

@jheer
Copy link
Member

jheer commented Jan 6, 2024

Thanks for the PR! We're going to have to think carefully whether or not we want to make this change. A few top of mind concerns that may not be reflected in the current test suite:

  • Possible performance issues. For example, does DuckDB actually optimize away the subquery when not needed?
  • Possible impacts on the DataCubeIndexer. We need to make sure that the static query analysis performed by the indexer still works as intended with changes to all generated mark queries.

I also need to think about any possible alternative approaches to achieving the desired functionality.

@jheer
Copy link
Member

jheer commented Jan 6, 2024

Just thinking through different options, one possibility might be to include an explicit key for window expressions. So alongside expr (for normal expressions) and agg (for aggregate expressions), we might add win or similar for window expressions. Generally I don't like growing the surface area this way if we can avoid it, but it would enable more targeted query generation if we identify any issues with using CTEs or subqueries by default.

One smaller change might be to use a chained subquery directly, rather than a CTE using with. Though in theory this should only be a syntactic change to the current PR, it is possible that this could be optimized differently depending on DB internals.

@frtennis1
Copy link
Contributor Author

From having used this change locally for a bit, if nothing else, I do find that the sql queries logged to the console get uglier / harder to debug with this change. So I am particularly sympathetic to something that does not change the queries where it's not needed (even if they get optimized away fully, which in the few examples I've looked at using duckdb's DESCRIBE it seemed like they were).

Unfortunately, I have a poor grasp of the DataCubeIndexer so I'm not sure about the implications there -- can just lend the data point that having used this change for a few weeks, I haven't seen any wonky behavior associated with this change.

If you've thought about it more and are on-board with it I can look into adding something like your suggestion of win.

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 this pull request may close these issues.

Window functions do not work in query with aggregate
2 participants