-
Notifications
You must be signed in to change notification settings - Fork 29.2k
[SPARK-56820][SQL] Add counter_diff window function for converting cumulative counters to delta format #55828
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
Closed
Closed
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
829733d
[SPARK-56820][SQL] Add counter_diff window function for converting cu…
pnikic-db 7306ed3
Address counter_diff PR comments
pnikic-db 11eca93
Address counter_diff PR comments - 2
pnikic-db f8f2acb
Improve PR with minor improvements
pnikic-db 9d23321
Improve PR with minor improvements - 2
pnikic-db File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -520,6 +520,7 @@ Window Functions | |
| .. autosummary:: | ||
| :toctree: api/ | ||
|
|
||
| counter_diff | ||
| cume_dist | ||
| dense_rank | ||
| lag | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -434,6 +434,7 @@ | |
| "var_samp", | ||
| "variance", | ||
| # Window Functions | ||
| "counter_diff", | ||
| "cume_dist", | ||
| "dense_rank", | ||
| "lag", | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(Late catch.) This 2-arg branch doesn't actually exercise the 2-arg form. At row 4 (
2024-01-02,c=50) the start_time advances AND the counter decreases, so both reset paths fire together — the 2-arg form returns NULL at row 4 because of either condition, and the expected output is byte-identical to the 1-arg form's expected output above. If you removed all start_time logic fromCounterDiffWithStartTime, this test would still pass.Compare to
DataFrameWindowFunctionsSuite.scala:835-857, where the two forms produce different outputs (Row(2, null)only in the 2-arg form because the start_time advances between rows 1 and 2 while the counter is still increasing) — that test does discriminate.Suggestion: shift the start_time advance to a row where the counter does not decrease, so the 2-arg form returns NULL while the 1-arg form returns a positive diff:
...combined with shifting row 3's
sttodatetime.datetime(2024, 1, 2)in the data fixture so the start_time advance happens between rows 2 and 3 (while the counter is still increasing from 200 to 400).test_connect_function.py::test_window_functionsseparately covers Connect↔Spark equivalence on a fuller dataset, but the unit test for the function itself should still be the place that distinguishes the two forms.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've changed the test to include both reset types separately: one for counter value decrease and one for start time increase. Thanks!