This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: sqlite3: expose sqlite3_create_window_function
Type: enhancement Stage: resolved
Components: Library (Lib) Versions: Python 3.9
process
Status: closed Resolution: duplicate
Dependencies: Superseder: Add create_window_function() to sqlite3.Connection
View: 34916
Assigned To: Nosy List: berker.peksag, erlendaasland, iljau
Priority: normal Keywords: patch

Created on 2020-05-13 18:52 by iljau, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
0001-Add-support-for-sqlite3-aggregate-window-functions.patch erlendaasland, 2020-05-24 21:50
Messages (6)
msg368794 - (view) Author: iljau (iljau) Date: 2020-05-13 18:52
Expose sqlite3_create_window_function as sqlite3.create_window_function.

There already exists sqlite3.create_aggregate, which uses sqlite3_create_function_v2 and is conceptually similar.

Window functions are available in sqlite starting from 2018-09-15 (3.25.0) release.

References:
https://www.sqlite.org/c3ref/create_function.html
https://www.sqlite.org/changes.html
msg369822 - (view) Author: Erlend E. Aasland (erlendaasland) * (Python triager) Date: 2020-05-24 20:24
This is a good idea, but I think the Python interface should stay the same.

From the user perspective, you'd only need to implement the 'value' and 'inverse' callbacks to transform your aggregate class into an aggregate window class.

From the CPython perspective, we'd only need to use sqlite3_create_window_function() instead of sqlite3_create_function_v2(), if we are compiling against SQLite 3.25.3 or newer.

I guess it would be nice to output a warning if the user aggregate class contains 'value' and 'inverse' callbacks, but sqlite3 _doesn't_ support aggregate window functions.
msg369828 - (view) Author: Erlend E. Aasland (erlendaasland) * (Python triager) Date: 2020-05-24 21:08
On a second thought and with regards to error reporting, it _would_ make sense to expose this as a function instead of embedding it into sqlite3.create_aggregate.
msg369834 - (view) Author: Erlend E. Aasland (erlendaasland) * (Python triager) Date: 2020-05-24 21:50
Please see attached patch, @iljau.
msg369851 - (view) Author: Erlend E. Aasland (erlendaasland) * (Python triager) Date: 2020-05-25 06:44
Another possibility (instead of adding `sqlite3.create_window_function`) is to add a "windowed" parameter to `sqlite3.create_aggregate()`:

`sqlite3.create_aggregate(name, narg, aggregate, windowed=True`

Maybe that's a little bit cleaner regarding the Python interface.
msg370880 - (view) Author: Erlend E. Aasland (erlendaasland) * (Python triager) Date: 2020-06-07 07:50
Duplicate of bpo-34916
History
Date User Action Args
2022-04-11 14:59:31adminsetgithub: 84797
2021-05-05 19:32:17erlendaaslandsetstatus: open -> closed
superseder: Add create_window_function() to sqlite3.Connection
resolution: duplicate
stage: resolved
2020-06-07 07:50:12erlendaaslandsetmessages: + msg370880
2020-05-25 06:44:46erlendaaslandsetmessages: + msg369851
2020-05-24 21:50:42erlendaaslandsetnosy: + berker.peksag
2020-05-24 21:50:27erlendaaslandsetfiles: + 0001-Add-support-for-sqlite3-aggregate-window-functions.patch
keywords: + patch
messages: + msg369834
2020-05-24 21:08:07erlendaaslandsetmessages: + msg369828
2020-05-24 20:24:17erlendaaslandsetnosy: + erlendaasland
messages: + msg369822
2020-05-13 18:52:51iljaucreate