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

[sqlite3] Add support for R*Tree callbacks #87620

Closed
erlend-aasland opened this issue Mar 9, 2021 · 6 comments
Closed

[sqlite3] Add support for R*Tree callbacks #87620

erlend-aasland opened this issue Mar 9, 2021 · 6 comments
Labels
stdlib Python modules in the Lib dir topic-sqlite3 triaged The issue has been accepted as valid by a triager. type-feature A feature request or enhancement

Comments

@erlend-aasland
Copy link
Contributor

BPO 43454
Nosy @berkerpeksag, @erlend-aasland
Files
  • patch.diff: Proof-of-concept
  • test_rtree.py
  • patch.diff: PoC patch with R*Tree autodetection
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = None
    created_at = <Date 2021-03-09.21:54:25.797>
    labels = ['type-feature', 'library', '3.10']
    title = '[sqlite3] Add support for R*Tree callbacks'
    updated_at = <Date 2021-03-24.22:57:09.732>
    user = 'https://github.com/erlend-aasland'

    bugs.python.org fields:

    activity = <Date 2021-03-24.22:57:09.732>
    actor = 'erlendaasland'
    assignee = 'none'
    closed = False
    closed_date = None
    closer = None
    components = ['Library (Lib)']
    creation = <Date 2021-03-09.21:54:25.797>
    creator = 'erlendaasland'
    dependencies = []
    files = ['49866', '49867', '49914']
    hgrepos = []
    issue_num = 43454
    keywords = ['patch']
    message_count = 5.0
    messages = ['388391', '388472', '388473', '388507', '389492']
    nosy_count = 2.0
    nosy_names = ['berker.peksag', 'erlendaasland']
    pr_nums = []
    priority = 'normal'
    resolution = None
    stage = None
    status = 'open'
    superseder = None
    type = 'enhancement'
    url = 'https://bugs.python.org/issue43454'
    versions = ['Python 3.10']

    @erlend-aasland
    Copy link
    Contributor Author

    Ref. bpo-43440

    Now that both Windows and macOS builds compile SQLite with R*Tree support, we should consider adding support for R*Tree callbacks.

    SQLite has two API's:

    • sqlite3_rtree_query_callback() for SQLite 3.8.5 and newer.
    • sqlite3_rtree_geometry_callback() for SQLite pre 3.8.5.

    I suggest using the new API only, because it is more flexible, and it is also the one recommended by SQLite.

    See https://sqlite.org/rtree.html

    Python API:
    sqlite3.Connection.create_rtree_query_function()

    Too long function name?

    As for the callback spec, I'm not sure what's the most pythonic approach?
    callback(coords, *params, **query_info):
    coords # array of coordinates of node or entry to check
    *params # parameters passed to the SQL function
    **query_info # the rest of the relevant sqlite3_rtree_query_info members
    return (visibility, score)

    @erlend-aasland erlend-aasland added 3.10 only security fixes stdlib Python modules in the Lib dir type-feature A feature request or enhancement labels Mar 9, 2021
    @erlend-aasland
    Copy link
    Contributor Author

    FYI, PoC patch attached. Lacks tests and some #ifdefs. Let me know if I should create a PR out of it.

    @erlend-aasland
    Copy link
    Contributor Author

    Test run output (see attached test file):

    $ ./python.exe test_rtree.py
    ARGS: ((-80.77490234375, -80.77469635009766, 35.377593994140625, 35.377803802490234), (45.3, 22.9, 5.0))
    KWARGS: {'num_queued': [0, 1], 'context': None, 'level': 0, 'max_level': 1, 'rowid': 1, 'parent_score': 0.0, 'parent_visibility': 1}
    ARGS: ((-81.0, -79.5999984741211, 35.0, 36.20000076293945), (45.3, 22.9, 5.0))
    KWARGS: {'num_queued': [1, 1], 'context': ['stuff'], 'level': 0, 'max_level': 1, 'rowid': 2, 'parent_score': 0.0, 'parent_visibility': 1}

    @erlend-aasland
    Copy link
    Contributor Author

    Unfortunately, there's no way to detect R*Tree support in sqlite3.h. We could run a script that dumps the compile options, and generate a config.h file from that:

    $ for L in $(sqlite3 ":memory:" "pragma compile_options"); do echo #define SQLITE_$L >> config.h; done
    $ cat config.h
    #define SQLITE_COMPILER=clang-12.0.0
    #define SQLITE_ENABLE_DBSTAT_VTAB
    #define SQLITE_ENABLE_FTS4
    #define SQLITE_ENABLE_FTS5
    #define SQLITE_ENABLE_GEOPOLY
    #define SQLITE_ENABLE_JSON1
    #define SQLITE_ENABLE_RTREE
    #define SQLITE_ENABLE_STMTVTAB
    #define SQLITE_THREADSAFE=1

    For Windows and macOS builds, we've already got the SQLite library compile options, so we can just reuse them in CFLAGS when we're building the sqlite3 module.

    @erlend-aasland
    Copy link
    Contributor Author

    Attached is a patch that auto-detects R*Tree support. Tested on macOS only, but I'd guess it should work fine on any OS.

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    @erlend-aasland erlend-aasland added topic-sqlite3 and removed 3.10 only security fixes labels May 16, 2022
    @erlend-aasland erlend-aasland added the triaged The issue has been accepted as valid by a triager. label Jul 25, 2022
    @erlend-aasland
    Copy link
    Contributor Author

    I have no bandwidth for driving this forward. Until there is a real feature request for this, I prefer to close this issue as not planned.

    @erlend-aasland erlend-aasland closed this as not planned Won't fix, can't repro, duplicate, stale Jan 22, 2023
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    stdlib Python modules in the Lib dir topic-sqlite3 triaged The issue has been accepted as valid by a triager. type-feature A feature request or enhancement
    Projects
    Status: Discarded
    Development

    No branches or pull requests

    1 participant