-
-
Notifications
You must be signed in to change notification settings - Fork 32.1k
gh-79097: Add support for aggregate window functions in sqlite3 #20903
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
Merged
Merged
Changes from 56 commits
Commits
Show all changes
57 commits
Select commit
Hold shift + click to select a range
bbef5a4
Add support for sqlite3 aggregate window functions
93bfb30
Add NEWS entry
7dfeb13
Add What's New
aaccca2
Merge branch 'main' into fix-issue-34916
718cc8c
Merge branch 'main' into fix-issue-34916
fb968ab
Merge branch 'main' into fix-issue-34916
00fb71c
Move What's New from 3.10 to 3.11
394c877
Merge branch 'main' into fix-issue-34916
8779a1b
Merge branch 'main' into fix-issue-34916
8ad68e2
Add traceback test
def7cbd
Merge branch 'main' into fix-issue-34916
60ac350
Improve coverage
a7eac02
Fix segfault with missing step method
0ba3ea1
Improve coverage
7d4f71c
Improve test namespace
99f0c84
Adjust fixme comment
f4fea56
Adjust docs
6f9c8c2
Merge branch 'main' into fix-issue-34916
44999be
Test unable to set return value in value callback
25ecc84
Make sure test db is committed
cd1cd66
Merge branch 'main' into fix-issue-34916
d73adc9
Convert to use the new callback_context struct
ff9c559
Merge branch 'main' into fix-issue-34916
397e05a
Use set_sqlite_error in. step callback
be2b54f
WIP
97d26c4
Merge branch 'main' into fix-issue-34916
388e5a3
Revert "WIP"
aeb7a9f
Merge branch 'main' into fix-issue-34916
1a49676
Merge branch 'main' into fix-issue-34916
6764984
Fix merge
f1331f2
Raise more accurate error messages for methods that are not defined
869559d
Merge branch 'main' into fix-issue-34916
6f5ed2b
Merge branch 'main' into fix-issue-34916
be8a4b5
Merge branch 'main' into fix-issue-34916
f173178
Fixup merge
0a3c0d5
Merge branch 'main' into fix-issue-34916
f1fe332
Improve docstring wording in example
1babe16
Use interned string for method lookup
0f06428
Test adjustments
61cdd90
Add tests for finalize errors, and missing finalize methods
6606760
Don't use stdbool
bbf0bab
Add keyword test
a4e0eb6
Use static inline iso. macro
d31f51f
No need to check if SQLITE_DETERMINISTIC is supported
2bb1ec2
Test that flags are keyword only
99b752f
Reduce PR: simplify API by excluding flags for now
81287f2
Remove keywords from docs
c66c992
Remove useless include
f442f77
Raise ProgrammingError if unable to create fn
cfc4d6f
Reword What's New and NEWS
9355614
Reword docs
d5b816d
Reword docstring
22fdb3d
Squeeze error handlers
217da20
Expand explanatory comment
6a789ac
Clean up tests
340cea9
Merge branch 'main' into fix-issue-34916
431ace8
Address review
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
# Example taken from https://www.sqlite.org/windowfunctions.html#udfwinfunc | ||
import sqlite3 | ||
|
||
|
||
class WindowSumInt: | ||
def __init__(self): | ||
self.count = 0 | ||
|
||
def step(self, value): | ||
"""Adds a row to the current window.""" | ||
self.count += value | ||
|
||
def value(self): | ||
"""Returns the current value of the aggregate.""" | ||
return self.count | ||
|
||
def inverse(self, value): | ||
"""Removes a row from the current window.""" | ||
self.count -= value | ||
|
||
def finalize(self): | ||
"""Returns the final value of the aggregate. | ||
|
||
Any clean-up actions should be placed here. | ||
""" | ||
return self.count | ||
|
||
|
||
con = sqlite3.connect(":memory:") | ||
cur = con.execute("create table test(x, y)") | ||
values = [ | ||
("a", 4), | ||
("b", 5), | ||
("c", 3), | ||
("d", 8), | ||
("e", 1), | ||
] | ||
cur.executemany("insert into test values(?, ?)", values) | ||
con.create_window_function("sumint", 1, WindowSumInt) | ||
cur.execute(""" | ||
select x, sumint(y) over ( | ||
order by x rows between 1 preceding and 1 following | ||
) as sum_y | ||
from test order by x | ||
""") | ||
print(cur.fetchall()) |
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
3 changes: 3 additions & 0 deletions
3
Misc/NEWS.d/next/Library/2020-05-24-23-52-03.bpo-40617.lycF9q.rst
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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
Add :meth:`~sqlite3.Connection.create_window_function` to | ||
:class:`sqlite3.Connection` for creating aggregate window functions. | ||
Patch by Erlend E. Aasland. |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.