Bind typed ARRAY/MAP values and LargeBinary correctly - #80
Open
aminghadersohi wants to merge 2 commits into
Open
aminghadersohi wants to merge 2 commits into
aminghadersohi wants to merge 2 commits into
Conversation
The warehouse ignores the elements of every Thrift ARRAY/MAP parameter encoding, so DatabricksArray/DatabricksMap values were persisted as empty collections without an error, and a NULL collection could not be bound. Send a typed value as one JSON string rebuilt with from_json(..., FAILFAST) (maps parsed with string keys and CAST to the declared type). LargeBinary binds raised AttributeError (the DB-API module has no Binary()) and raw bytes were sent as an ARRAY parameter; bind them as a hex string decoded with unhex().
aminghadersohi
requested review from
deeksha-db,
gopalldb,
jackyhu-db,
jayantsing-db,
jprakash-db,
samikshya-db,
shivam2680 and
vikrantpuppala
as code owners
September 26, 2026 09:55
Serializing collection values to JSON skipped each element type's own bind processor, so DatabricksArray(Uuid), DatabricksArray(Time) and DatabricksMap(Uuid, ...) raised TypeError. Run the element's and key's dialect bind processor before serializing. Numeric has no bind processor here, so decimals still serialize exactly.
This branch has not been deployed
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.
What type of PR is this?
Description
Problem
DatabricksArray/DatabricksMapbinds hand a Python list/dict to the connector, which sends an ARRAY/MAP parameter. On the SQL warehouse I tested (databricks-sql-connector 4.6.0), the elements of such a parameter were ignored under every Thrift encoding I tried (protocol versions V7–V9), so the row was written with an empty collection and no error (as reported in Unable to insert Python lists into ARRAY<STRING> columns using pandas to_sql #73). This may depend on the connector and warehouse version: the repository's integration run onmain(June 2026, locked connector) passed. ANULLcollection column cannot be bound at all ('NoneType' object is not iterable).Binary()constructor, whichdatabricks.sqldoes not define (AttributeError). Rawbytesare aSequence, so the connector sends them as an ARRAY, and the warehouse rejectsBINARYas a parameter type (INVALID_PARAMETER_MARKER_VALUE.INVALID_DATA_TYPE).Change
from_json(:p, '<schema>', map('mode', 'FAILFAST')). JSON object keys are strings, so maps parse asMAP<STRING, V>and areCASTto the declared type.FAILFASTmakes malformed JSON fail the statement instead of becoming NULL. For maps, theCASTalso rejects keys that can't be converted when ANSI mode is on. The SQL does not depend on the element count and uses no lambdas (the warehouse rejectstransforminsideINSERT ... VALUES), so multi-row VALUES and executemany work. Each element and key first goes through its own type's bind processor (soUuid,TimeandTypeDecoratorelements behave as before). Decimals then serialize as plain digits, dates/datetimes as ISO 8601 strings, andNoneas SQL NULL.colspecs) toDatabricksBinary, which binds a hex string decoded withunhex().How is this tested?
Unit tests
E2E Tests
Manually
N/A
New
tests/test_local/test_collection_binds.py: 4 tests that fail onmainand pass here, plus a test thatUuid/Timeelements andUuidmap keys still go through their bind processors. The local unit suite (tests/test_local, excluding e2e) passes (304), andblack --check srcand mypy are clean.Live check on a SQL warehouse (SQLAlchemy 2.0.52, databricks-sql-connector 4.6.0): a Core executemany of
ARRAY<BIGINT>[9007199254740993, NULL],MAP<INT,STRING>{7: '雪'},ARRAY<DECIMAL(38,18)>, all 256 byte values in aBINARYcolumn, plus NULL and empty collections, read back exactly. Date/timestamp elements are covered by unit tests only.Related Tickets & Documents
Fixes #73.