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

SNOW-1491329 Support window functions in Snowpark IR #1914

Merged

Conversation

sfc-gh-lspiegelberg
Copy link
Contributor

@sfc-gh-lspiegelberg sfc-gh-lspiegelberg commented Jul 15, 2024

Support window functions/expressions in Snowpark IR.

@sfc-gh-lspiegelberg sfc-gh-lspiegelberg changed the base branch from main to server-side-snowpark July 15, 2024 22:50
@sfc-gh-lspiegelberg sfc-gh-lspiegelberg changed the title [DRAFT] SNOW-1491329 window functions SNOW-1491329 Support window functions in Snowpark IR Jul 16, 2024
ast = proto.SpWindowSpecExpr()
window_ast = with_src_position(ast.sp_window_spec_order_by)
window_ast.wnd.CopyFrom(self._ast)
for e in exprs:
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there's some code duplication here, could use helper function. For now kept as is to not introduce complexity.


res2 = res1.select(col("NUM").as_("key"), col("STR").as_("value"))

res3 = res2.select(avg(col("value")).over(Window.partition_by(col("value")).order_by(col("key")).rows_between(0, 2)).as_("window1"), avg(col("value")).over(Window.order_by(col("key").desc()).range_between(-9223372036854775807, 9223372036854775807)).as_("window2"))
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note here that the constants Window.CURRENT_ROW are internally labels for integers. I left a comment here https://github.com/snowflakedb/snowflake/pull/194828/files#r1679926588 to discuss strategies.

@sfc-gh-lspiegelberg sfc-gh-lspiegelberg marked this pull request as ready for review July 16, 2024 19:00
@sfc-gh-lspiegelberg sfc-gh-lspiegelberg requested a review from a team as a code owner July 16, 2024 19:00
@sfc-gh-lspiegelberg sfc-gh-lspiegelberg merged commit ebe4503 into server-side-snowpark Jul 17, 2024
12 of 14 checks passed
@sfc-gh-lspiegelberg sfc-gh-lspiegelberg deleted the ls-SNOW-1491329-window-functions branch July 17, 2024 16:18
@github-actions github-actions bot locked and limited conversation to collaborators Jul 17, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants