Skip to content

[SPARK-56729][SQL] ReplaceData and WriteDelta should implement SupportsNonDeterministicExpression#55692

Open
pabloggarc wants to merge 2 commits intoapache:masterfrom
pabloggarc:SPARK-56729-replacedata-nondeterministic
Open

[SPARK-56729][SQL] ReplaceData and WriteDelta should implement SupportsNonDeterministicExpression#55692
pabloggarc wants to merge 2 commits intoapache:masterfrom
pabloggarc:SPARK-56729-replacedata-nondeterministic

Conversation

@pabloggarc
Copy link
Copy Markdown

What changes were proposed in this pull request?

ReplaceData and WriteDelta now implement the SupportsNonDeterministicExpression trait (introduced in SPARK-48871). This fixes INVALID_NON_DETERMINISTIC_EXPRESSIONS errors when running MERGE INTO on DSv2 tables (e.g. Apache Iceberg) where the source plan contains non-deterministic expressions such as uuid(), current_timestamp(), or input_file_name().

Why are the changes needed?

In Spark 3.5, RewriteMergeIntoTable wraps the source plan in an Exists subquery stored as groupFilterCondition on ReplaceData. If the source plan contains any non-deterministic expression, the Exists becomes non-deterministic and CheckAnalysis rejects the query. The SupportsNonDeterministicExpression trait was introduced in SPARK-48871 for exactly this situation, but was never applied to ReplaceData or WriteDelta. This is a regression from Spark 3.3, where these queries worked correctly.

Root cause analysis by @DaxterXS in apache/iceberg#14585. Multiple users affected across AWS Glue 4/5 with Iceberg 1.7–1.10.

Does this PR introduce any user-facing change?

Yes. MERGE INTO queries with non-deterministic expressions in the source plan will no longer fail with INVALID_NON_DETERMINISTIC_EXPRESSIONS.

How was this patch tested?

Added unit tests in AnalysisErrorSuite verifying that ReplaceData and WriteDelta implement SupportsNonDeterministicExpression.

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

No.

pabloggarc and others added 2 commits May 5, 2026 23:54
…tsNonDeterministicExpression

Co-authored-by: DaxterXS <DaxterXS@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant