feat(backend/kernel): wire TSparkParameter through to kernel bind_param#789
Open
vikrantpuppala wants to merge 1 commit into
Open
feat(backend/kernel): wire TSparkParameter through to kernel bind_param#789vikrantpuppala wants to merge 1 commit into
vikrantpuppala wants to merge 1 commit into
Conversation
24e9a5c to
5a6f1f0
Compare
Lifts the NotSupportedError that execute_command currently raises
for parametrized queries. The kernel-side PyO3 binding for
Statement.bind_param landed in databricks-sql-kernel#18; this
commit wires the connector's TSparkParameter shape through to it.
Implementation:
- New `bind_tspark_params(kernel_stmt, parameters)` in
type_mapping.py forwards each TSparkParameter to the kernel as
`(ordinal, value.stringValue, type)`. ordinal is the 1-based
position in the parameters list; the connector's `ordinal: bool`
flag is checked only to reject named bindings (kernel v0 doesn't
accept them on the wire).
- execute_command no longer raises on `parameters=[...]`. The
query_tags branch stays — that's a separate gap.
Tests:
- 6 new unit tests in tests/unit/test_kernel_type_mapping.py for
the mapper:
- positional forwarding preserves ordering and (ordinal, value, type)
- None value forwards as SQL NULL
- VOID passes through verbatim (kernel parser ignores value for VOID)
- named bindings raise NotSupportedError with a pointed message
- missing TSparkParameter.type defaults to STRING (defensive)
- empty parameters list is a no-op
- `test_execute_command_rejects_parameters` (which previously
asserted the NotSupportedError) replaced with
`test_execute_command_forwards_parameters_to_bind_param` — stubs
the kernel statement and verifies bind_param is called once per
TSparkParameter in order with 1-based ordinals, and execute
fires after binding.
- 3 new e2e tests in tests/e2e/test_kernel_backend.py against
dogfood:
- mixed-type round-trip (INT, STRING, BOOLEAN) via the
connector's native IntegerParameter/StringParameter/BooleanParameter
- None parameter (VoidParameter → SQL NULL)
- DECIMAL parameter with precision/scale carried in the SQL type
string (auto-inferred — explicit-arg path has a pre-existing
bug in native.py where format-args are swapped)
106/106 kernel unit tests pass.
Co-authored-by: Isaac
Signed-off-by: Vikrant Puppala <vikrant.puppala@databricks.com>
aa8bd24 to
19c0bb6
Compare
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.
Summary
Lifts the
NotSupportedErrorthe kernel backend currently raises for parametrized queries. The kernel-side PyO3 binding (Statement.bind_param) shipped in databricks-sql-kernel#18; this PR wires the connector'sTSparkParametershape through to it.Before:
cursor.execute("SELECT ?", [IntegerParameter(42)])onuse_kernel=TrueraisedNotSupportedError. After: positional parameter binding works end-to-end.What it does
bind_tspark_params(kernel_stmt, parameters)intype_mapping.pyforwards eachTSparkParameterto the kernel as(ordinal, value.stringValue, type):ordinalis the 1-based position in the parameters list (matches kernel's SEA-wire convention).value.stringValueis the connector's already-string-encoded value (orNonefor SQL NULL).typeis the SQL type name the connector produces ("INT","DECIMAL(10,2)", etc.).The connector's
ordinal: boolflag is checked only to reject named bindings — kernel v0 doesn't accept named bindings on the SEA wire, so we surface that at the connector layer with a pointedNotSupportedErrorrather than letting the server reject.What's supported
Every type the connector's native parameter classes emit:
BOOLEAN,TINYINT/SMALLINT/INT/BIGINT,FLOAT/DOUBLESTRING,DATE,TIMESTAMP/TIMESTAMP_NTZ,INTERVALDECIMAL(p,s)(precision/scale carried in the SQL type string; kernel parses them)VOID/ PythonNoneWhat's not supported (known gaps, raises
NotSupportedError)cursor.execute(":foo = ?", [param_named("foo", ...)])) — kernel v0 SEA wire is positional-only.ARRAY/MAP/STRUCT) — kernel parser rejects; surfaces asKernelError(InvalidArgument).BINARY— SEA wire limitation kernel-side; documented workaround is hex-encode +unhex(?)in SQL.Test plan
tests/unit/test_kernel_type_mapping.pyforbind_tspark_params— positional forwarding,None/VOID, named-binding rejection, missing-type defaulting, empty list.test_execute_command_rejects_parameters(which previously asserted theNotSupportedError) withtest_execute_command_forwards_parameters_to_bind_param: stubs the kernel statement, assertsbind_paramis called once perTSparkParameterin order with 1-based ordinals, andexecute()fires after binding.main).tests/e2e/test_kernel_backend.pyagainst dogfood:IntegerParameter,StringParameter,BooleanParameter)NoneparameterDECIMALparameter (precision/scale flows through the SQL type string)databricks-sql-kernelmain).This pull request and its description were written by Isaac.