Skip to content

Conversation

bersprockets
Copy link
Contributor

What changes were proposed in this pull request?

Change ExpandExec#doExecute to initialize the unsafe projections before using them.

Why are the changes needed?

The unsafe projections might contain non-deterministic expressions, and non-deterministic expressions must be initialized before used.

For example, see the test added by this PR (which is essentially the test right above it, except with whole-stage codegen turned off). In the case where the "split-updates" property is set to "true", RewriteUpdateTable will create an Expand operator with a set of projections, one of which will contain a nondeterministic expression (the assignment value). ExpandExec fails to initialize the derived UnsafeProjections before using them, resulting in a NullPointerException:

[info]   org.apache.spark.SparkException: Job aborted due to stage failure: Task 0 in stage 11.0 failed 1 times, most recent failure: Lost task 0.0 in stage 11.0 (TID 11) (10.0.0.101 executor driver):
java.lang.NullPointerException: Cannot invoke "java.util.Random.nextDouble()" because "<parameter1>.mutableStateArray_0[0]" is null
[info] 	at org.apache.spark.sql.catalyst.expressions.GeneratedClass$SpecificUnsafeProjection.writeFields_0_0$(Unknown Source)
[info] 	at org.apache.spark.sql.catalyst.expressions.GeneratedClass$SpecificUnsafeProjection.apply(Unknown Source)
[info] 	at org.apache.spark.sql.execution.ExpandExec$$anon$1.next(ExpandExec.scala:75)
...

Does this PR introduce any user-facing change?

No.

How was this patch tested?

New test.

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

@github-actions github-actions bot added the SQL label Sep 9, 2025
@HyukjinKwon
Copy link
Member

Merged to master.

Copy link
Member

@dongjoon-hyun dongjoon-hyun left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1, LGTM.

Could you make backporting PRs, @bersprockets ?

bersprockets added a commit to bersprockets/spark that referenced this pull request Sep 10, 2025
Change `ExpandExec#doExecute` to initialize the unsafe projections before using them.

The unsafe projections might contain non-deterministic expressions, and non-deterministic expressions must be initialized before used.

For example, see the test added by this PR (which is essentially the test right above it, except with whole-stage codegen turned off). In the case where the "split-updates" property is set to "true", `RewriteUpdateTable` will create an `Expand` operator with a set of projections, one of which will contain a nondeterministic expression (the assignment value). `ExpandExec` fails to initialize the derived `UnsafeProjection`s before using them, resulting in a `NullPointerException`:
```
[info]   org.apache.spark.SparkException: Job aborted due to stage failure: Task 0 in stage 11.0 failed 1 times, most recent failure: Lost task 0.0 in stage 11.0 (TID 11) (10.0.0.101 executor driver):
java.lang.NullPointerException: Cannot invoke "java.util.Random.nextDouble()" because "<parameter1>.mutableStateArray_0[0]" is null
[info] 	at org.apache.spark.sql.catalyst.expressions.GeneratedClass$SpecificUnsafeProjection.writeFields_0_0$(Unknown Source)
[info] 	at org.apache.spark.sql.catalyst.expressions.GeneratedClass$SpecificUnsafeProjection.apply(Unknown Source)
[info] 	at org.apache.spark.sql.execution.ExpandExec$$anon$1.next(ExpandExec.scala:75)
...
```

No.

New test.

Closes apache#52292 from bersprockets/upd_del_oddity.

Authored-by: Bruce Robbins <bersprockets@gmail.com>
Signed-off-by: Hyukjin Kwon <gurwls223@apache.org>
dongjoon-hyun pushed a commit that referenced this pull request Sep 12, 2025
…jections

### What changes were proposed in this pull request?

This PR back-ports #52292.

Change `ExpandExec#doExecute` to initialize the unsafe projections before using them.

### Why are the changes needed?

The unsafe projections might contain non-deterministic expressions, and non-deterministic expressions must be initialized before used.

For example, see the test added by this PR (which is essentially the test right above it, except with whole-stage codegen turned off). In the case where the "split-updates" property is set to "true", `RewriteUpdateTable` will create an `Expand` operator with a set of projections, one of which will contain a nondeterministic expression (the assignment value). `ExpandExec` fails to initialize the derived `UnsafeProjection`s before using them, resulting in a `NullPointerException`:
```
[info]   org.apache.spark.SparkException: Job aborted due to stage failure: Task 0 in stage 11.0 failed 1 times, most recent failure: Lost task 0.0 in stage 11.0 (TID 11) (10.0.0.101 executor driver):
java.lang.NullPointerException: Cannot invoke "java.util.Random.nextDouble()" because "<parameter1>.mutableStateArray_0[0]" is null
[info] 	at org.apache.spark.sql.catalyst.expressions.GeneratedClass$SpecificUnsafeProjection.writeFields_0_0$(Unknown Source)
[info] 	at org.apache.spark.sql.catalyst.expressions.GeneratedClass$SpecificUnsafeProjection.apply(Unknown Source)
[info] 	at org.apache.spark.sql.execution.ExpandExec$$anon$1.next(ExpandExec.scala:75)
...
```

### Does this PR introduce _any_ user-facing change?

No.

### How was this patch tested?

New test.

Closes #52319 from bersprockets/upd_del_oddity_br40.

Authored-by: Bruce Robbins <bersprockets@gmail.com>
Signed-off-by: Dongjoon Hyun <dongjoon@apache.org>
@bersprockets bersprockets deleted the upd_del_oddity branch September 12, 2025 17:21
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.

3 participants