gengliangwang opened a new pull request, #56230:
URL: https://github.com/apache/spark/pull/56230
### What changes were proposed in this pull request?
In `GenerateOrdering.genComparisons`, each order key emits a four-way
branch: `if (l.isNull && r.isNull) {} else if (l.isNull) {..} else if
(r.isNull) {..} else { compare }`. When the order key is statically
non-nullable, both `l.isNull` and `r.isNull` are `FalseLiteral`, so the three
null-handling branches are dead and only the `else { compare }` ever runs.
This patch detects that case (`l.isNull == FalseLiteral && r.isNull ==
FalseLiteral` -- the same idiom `GenerateUnsafeProjection` uses) and emits only
the value comparison, wrapped in a block so `comp` stays scoped when
`splitExpressions` concatenates multiple comparisons. The nullable path is
unchanged.
### Why are the changes needed?
Part of SPARK-56908 (umbrella). `GenerateOrdering` backs `SortExec`, range
partitioning, window, and sort-merge join; sort keys are very commonly
non-nullable, so this removes dead branches from a hot, widely-generated
comparator (helping with the JVM 64KB method / constant-pool limits, Janino
compile time, and JIT work).
### Does this PR introduce _any_ user-facing change?
No. The compiled behavior is identical; only the emitted Java source text
changes.
### How was this patch tested?
Added `GenerateOrdering with non-nullable keys: <type>` cases to
`OrderingSuite` (atomic + complex types, mixed asc/desc to cover both the
`comp` and `-comp` emissions, two keys to cover the `comp` scoping),
cross-checked against `InterpretedOrdering`.
```
build/sbt "catalyst/testOnly *OrderingSuite" # 89/89
build/sbt "sql/testOnly org.apache.spark.sql.execution.SortSuite" # 255/255
```
### Was this patch authored or co-authored using generative AI tooling?
Generated-by: Claude Code (Opus 4.8)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]