Repository navigation
Implement Python DB-API 2.0 compliance - #19369
Open
hongzhi-gao wants to merge 9 commits into
Open
hongzhi-gao wants to merge 9 commits into
hongzhi-gao wants to merge 9 commits into
Conversation
Default DB-API connections to the table dialect and support typed pyformat parameters, streaming tuple results, standard metadata and exceptions. Preserve nanosecond timestamps, synchronize database changes and correct fetch-size/timeout arguments. Report unsupported rollback explicitly. Remove SQLAlchemy-specific result rewriting from the generic DB-API and reject the legacy adapter mode pending separate SQLAlchemy adaptation. Document the supported interface and add contract and round-trip tests. Validation: 105 unit tests and 6 DB-API integration tests against a local Edge server passed; Black, diff checks and wheel build passed.
Caideyipi
requested changes
Nov 23, 2026
Caideyipi
left a comment
Collaborator
There was a problem hiding this comment.
Reviewed head 2e1d9c85d0b65a56965482a47f1c73793ee00781 against base aa116e0b9656da943cfd7eea108f8da4affa6d3b. I found two correctness issues: empty positional parameter sequences fail on statements with no placeholders, and tree-dialect rows expose the implicit timestamp as an integer rather than a Python datetime as documented. git diff --check passes. I did not run the Python suite locally; several CI checks remain pending.
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Background
The IoTDB Python client already exposed a DB-API interface, but several behaviors differed from PEP 249. SQL execution errors could be swallowed and presented as empty results, making failures indistinguishable from successful queries with no rows. Parameters were interpolated with Python string formatting without consistent validation. Results were materialized through a DataFrame, cursor behavior and cleanup were inconsistent, and rollback() silently returned even though IoTDB does not support transactions.
Changes
Example parameterized query:
Impact on existing Python APIs
fetch_sizeoption onSession.execute_statement()defaults toNone. If omitted, the request does not set the ThriftfetchSizefield, so the Session does not impose a new client-side fetch-size default. The DB-API cursor explicitly passes the value configured throughconnect(fetch_size=...). The existingtimeoutargument continues to be sent as before.USEstatement now updates the Session's remembered database. If the connection is re-established later, the Session restores that database. This makes queries after reconnect continue in the database selected byUSE.PEP 249 interface checklist
Status: Supported means the interface is provided. Limited means it is provided with an IoTDB-specific constraint. Not implemented means the optional API is absent. PEP 249 optional extensions are not required for core compliance.
Module interface
Exceptions
Connection methods
Cursor attributes and methods
Type objects and constructors
Optional interfaces and extensions
Tests
Added a dedicated PEP 249 contract test module at tests/unit/dbapi/test_pep249.py. It groups checks by the checklist above and covers module attributes, exception inheritance, connection and transaction methods, cursor metadata and fetching, type constructors, and supported optional extensions. Existing DB-API tests continue to cover parameter edge cases, status-code mapping, timestamp precision, reconnect behavior, and SQLAlchemy time-column compatibility.
Validation: python -m pytest tests/unit/dbapi -q — 82 passed. Thrift Python sources were generated with the repository Maven Wrapper.
Scope
This PR focuses on DB-API 2.0 behavior and compatibility with the existing experimental SQLAlchemy dialect. SQLAlchemy table-model support and integrations with pandas, Superset, and other upper-layer applications are outside this PR.