Lokasi ngalangkungan proxy:   [ UP ]  
[Ngawartoskeun bug]   [Panyetelan cookie]                
Skip to content

[SPARK-58782][SQL][4.0] Fix DSv2 pushdown null literal serialization bug - #61177

Open
RonakkGovani wants to merge 1 commit into
apache:branch-4.0from
RonakkGovani:SPARK-58782-backport-4.0
Open

RonakkGovani wants to merge 1 commit into
apache:branch-4.0from
RonakkGovani:SPARK-58782-backport-4.0

Conversation

@RonakkGovani

Copy link
Copy Markdown
Contributor

What changes were proposed in this pull request?

Backport of #58023 to branch-4.0.

LiteralValue.toString matched on the data type even when the value was null, so a null literal rendered as 'null' for strings and failed an assertion for BINARY. It now renders a null value as NULL first.

The cherry-pick had conflicts on branch-4.0, which I resolved without other changes: LiteralValue.toString keeps its StringUtils.replace and Hex.encodeHexString helpers inside the new null check, and JDBCV2Suite creates the null_literal table in its existing setup instead of the batched setup of master.

Why are the changes needed?

Without it, branch-4.0 has both bugs that #58023 fixed on master, branch-4.x and branch-4.3. For example, SPARK-62633 reports that on 4.1.2 pushing down bin_col IN (X'31', NULL) to a DSv2 source such as Iceberg fails with INTERNAL_ERROR from java.lang.AssertionError in LiteralValue.toString, and a pushed-down NULLIF(s, '') groups the empty string under a 'null' string group.

Does this PR introduce any user-facing change?

Yes. A null literal in a pushed-down DSv2 expression renders as NULL, so pushing down a null BINARY literal no longer fails, and JDBC pushdown no longer compares with the string 'null'.

How was this patch tested?

Ran LiteralValueSuite, including the null BinaryType case, and JDBCV2Suite on branch-4.0.

Was this patch authored or co-authored using generative AI tooling?

Generated-by: Isaac (Claude Opus 5.5), used to prepare this backport. The change itself is #58023 by @pratham76.

This pull request and its description were written by Isaac.

This PR fixes a bug where null literals were incorrectly serialized as the string 'null' instead of the SQL keyword NULL when pushed down to external databases via DSv2 (JDBC aggregate/predicate pushdown).

`LiteralValue.toString` - the only toString for DSv2's only concrete Literal, and the path every pushdown rendering (explain strings, generated SQL) ultimately goes through,  matched on dataType even when the value was null, instead of checking for null first. This produced two distinct, user-visible bugs:

* For StringType, a null value rendered as the quoted string 'null' instead of NULL. When pushed down (e.g. NULLIF(s, ''), which rewrites to If(s = '', null, s)), the empty-string row was grouped under the literal string "null" instead of collapsing into the real NULL group — the external database executed a different grouping key than intended, producing 3 result rows instead of 2.

* For BinaryType, the branch ran assert(value.isInstanceOf[Array[Byte]]), which fails on null and threw an AssertionError when rendering a pushed expression containing a null binary literal, rather than merely producing bad SQL.

Yes - Query results will now be correct when null literals are pushed down to external databases via JDBC.

_Before the fix:_ A query with NULLIF(col, '') in a GROUP BY would push down CASE WHEN col = '' THEN 'null' ELSE col END to the database, creating a spurious 'null' string group instead of a NULL group.

_After the fix:_ The same query pushes down CASE WHEN col = '' THEN NULL ELSE col END, correctly collapsing empty strings into the NULL group as intended. Null binary literals render as NULL without error.

* Unit tests in LiteralValueSuite covering all data types
* End-to-end regression test in JDBCV2Suite with H2 database
* Updated existing test expectations that relied on the old (incorrect) behavior

No

Closes apache#58023 from pratham76/SPARK-58782.

Authored-by: Pratham Manja <prathammanja76@gmail.com>
Signed-off-by: Szehon Ho <szehon.apache@gmail.com>
(cherry picked from commit 01b0663)

Resolved conflicts for branch-4.0: kept its StringUtils.replace and Hex.encodeHexString helpers in LiteralValue.toString, and created the null_literal table in the existing JDBCV2Suite setup.

Co-authored-by: Isaac <no-reply@databricks.com>
@github-actions github-actions Bot added the SQL label Dec 4, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants