Repository navigation
Conversation
Since 4.0.4, inline parameters render every Python sequence as an ARRAY literal, so the documented `x IN %(ids)s` pattern produces `x IN ARRAY(1,2,3)`, which Spark rejects with PARSE_SYNTAX_ERROR. A sequence whose marker directly follows IN (or NOT IN) now renders as a parenthesised list again. Everywhere else, including `IN (%(p)s)` where the caller wrote the parentheses, it stays an ARRAY literal, so inline writes to ARRAY columns keep working. Because `x IN ARRAY(...)` never parses, no query that runs today renders differently. Co-authored-by: Isaac <no-reply@databricks.com> Signed-off-by: cathleen.yan <58714163+cathleeny@users.noreply.github.com>
This branch was successfully 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
Why: Since 4.0.4 (#559), inline parameters (
use_inline_params=True) render every Python sequence as anARRAY(...)literal. TheWHERE x IN %(ids)spattern documented indocs/parameters.mdtherefore renders asx IN ARRAY(1,2,3), which Spark rejects withPARSE_SYNTAX_ERROR, and that blocks users moving from 3.x.Change: A sequence whose marker directly follows
INorNOT INrenders as a parenthesised list,(1,2,3), again. Everywhere else it stays anARRAY(...)literal, includingIN (%(p)s)where the caller wrote the parentheses. That keeps the inline writes toARRAYcolumns added in #559 working. Becausex IN ARRAY(...)never parses, no query that runs today renders differently.To find which markers follow
IN, the operation is formatted once with placeholder values through the same%formatting thatinject_parametersuses. That keeps positional markers and%%aligned with the real substitution, and malformed operations raise the same errors as before.docs/parameters.mdnow notes that the marker must directly followIN.Scope notes:
Cursor._prepare_inline_parametersbefore backend dispatch, so the fix covers the Thrift, SEA and kernel backends. The kernel receives the already-rendered SQL and does no SQL-text interpolation of its own.IN (). Spark rejects that (PARSE_SYNTAX_ERROR, orINVALID_SQL_SYNTAX.EMPTY_IN_PREDICATEsince SPARK-54634), the same as on 3.x.ARRAYliterals, so multi-column(a, b) IN %swith a list of tuples is not restored to its 3.x rendering.INby a comment, and positional queries that also use%d-style markers, keep theARRAYrendering.(...). That would break the inlineARRAYinserts covered bytest_primitive_single[INLINE-ARRAYS]andtest_inline_recursive_complex_type, so this change only targets theINposition.How is this tested?
Unit tests
E2E Tests
Manually
Unit:
TestInClauseSequenceRenderingcovers named and positional markers,NOT IN, escaped strings, nested sequences,%%, and a lowercaseinfollowed by a newline. It also pinsARRAYrendering forINSERT ... VALUES, function arguments andIN (%(p)s), and checks that a malformed operation still raises the sameTypeError.test_execute_inline_sequence_after_in_renders_as_listgoes throughCursor.execute. It failed onmainwithIN ARRAY(1,2,3).blackandmypyare clean onsrc.E2E:
test_inline_sequence_in_clausecovers named, positional andNOT INcases againstrange(5). I have not run it locally because it needs warehouse credentials.Manual: On a Databricks SQL warehouse, the SQL these cases render to returned the expected rows, and
2 IN ARRAY(1,2,3)failed withPARSE_SYNTAX_ERROR.Related Tickets & Documents
Fixes #629
ES-2336977
This pull request and its description were written by Isaac.