fix(#654): bind UUID array parameters for PostgreSQL ADBC - #656
Merged
Conversation
PostgreSQL-family ADBC formatted every UUID parameter as str(UUID(str(value))), re-parsing values that were already UUID objects before formatting them a second time. Format UUID objects directly and reserve parsing for string inputs, which are the only values that need validating and canonicalizing. Bound values are unchanged. Measured over 10k single-ordinal rows, UUID-object conversion drops from 26.5ms to 10.0ms; the string path is unaffected. Also pins the conversion contract with tests: bare strings are never detected as UUIDs on the single-execution path, while every parseable string form canonicalizes on the batch path once a UUID object establishes the ordinal.
Binding a list of UUIDs as one PostgreSQL array parameter failed before reaching the database. PyArrow 25 cannot build a nested extension array from Python objects at all, so the only workable representation is a string array plus an explicit UUID[] cast. Detection now classifies each parameter as a scalar UUID or a UUID array by peeking at the first non-null element of a sequence, and the SQL rewrite emits CAST($n AS UUID[]) for array ordinals. A caller-written UUID[] cast is recognized as satisfying that requirement rather than treated as a foreign cast, which previously caused the values to be left unconverted. Both ordinal kinds share the existing memoized rewrite. Also fixes a related failure where a UUID that is a statement's only parameter reached PostgreSQL as bytea. UUID types were absent from the ADBC type coercion map, so a lone UUID argument took the statement cache fast path and skipped UUID binding entirely on every execution after the first. Existing coverage missed this because its statements always bound an integer alongside the UUID, which forced the slower path. Arrays containing None are rejected with an explicit message: the PostgreSQL ADBC driver encodes null array elements as empty strings, which PostgreSQL rejects for UUID[]. Empty, all-null, and non-UUID-headed sequences are left untouched. Statement name generation now uses the shared UUID helper, which prefers the accelerated implementation when it is installed. Fixes #654.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #656 +/- ##
=======================================
Coverage 77.11% 77.11%
=======================================
Files 475 475
Lines 67363 67422 +59
Branches 9209 9226 +17
=======================================
+ Hits 51945 51992 +47
- Misses 12021 12029 +8
- Partials 3397 3401 +4
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
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.
Binding a list of UUIDs as a single PostgreSQL array parameter through an ADBC driver failed before the query ever reached the database. This makes UUID arrays bind correctly, and along the way fixes a separate case where a UUID that was a statement's only parameter reached PostgreSQL as
bytea.WHERE id = ANY(CAST(? AS UUID[]))work, and the cast is added automatically when the query does not already supply one. PyArrow cannot build a nested extension array from Python objects at all, so the values are sent as a string array with an explicitUUID[]cast.UUID[]cast used to be treated as a foreign cast, which silently left the values unconverted.bytea. A statement whose only parameter was a UUID skipped UUID binding on every execution after the first, because it took a cached fast path. Statements that bound anything alongside the UUID were unaffected, which is why this went unnoticed.Nonenow raise a clear error. The PostgreSQL ADBC driver encodes a null array element as an empty string, which PostgreSQL rejects forUUID[]; previously this surfaced as an opaqueinvalid input syntax for type uuidfailure from the server.Empty sequences, all-
Nonesequences, and sequences that do not start with a UUID are left untouched, as are non-PostgreSQL ADBC backends.Fixes #654.