haziqishere opened a new pull request, #7704:
URL: https://github.com/apache/datafusion-comet/pull/7704
## Which issue does this PR close?
<!--
We generally require a GitHub issue to be filed for all bug fixes and
enhancements and this helps us generate change logs for our releases. You can
link an issue to this PR using the GitHub syntax. For example `Closes #123`
indicates that this PR will close issue #123.
-->
Closes #7703
## Rationale for this change
<!--
Why are you proposing this change? If this is already explained clearly in
the issue then this section is not needed.
Explaining clearly why changes are proposed helps reviewers understand your
changes and offer better suggestions for fixes.
-->
Native shuffle reads Arrow-backed `CometVector`s, but
`CometShuffleExchangeExec` accepts any columnar child. When the child turns
row-based after Comet chose native shuffle, Spark inserts `RowToColumnarExec`
under the exchange. `EliminateRedundantTransitions` removes that transition
under a JVM columnar shuffle, but has no case for native shuffle, so
`reconcileStreamSchema` gets Spark's `OnHeapColumnVector`/`OffHeapColumnVector`
and fails every task with a `ClassCastException`.
This happens on Amazon EMR, whose AQE wraps a reused exchange's child in a
nested `AdaptiveSparkPlanExec` that reports row-based output. I haven't found
an Apache Spark 4.1 plan that reaches it, so on Apache Spark this is hardening;
the test builds the plan by hand and gets the same exception. #6607 handled the
same cast for a different trigger (`transitionRevert`); #6685 is a different
failure in the same code path, with Comet's own converter as the child.
## What changes are included in this PR?
<!--
There is no need to duplicate the description in the issue here but it is
sometimes worth providing a summary of the individual changes in this PR.
-->
- `EliminateRedundantTransitions`: a native `CometShuffleExchangeExec`
over `RowToColumnarExec` drops the transition and switches to
`CometColumnarShuffle`, which reads rows. Tags are copied to the new node, as
`RevertNativeForTransitionHeavyStages` does for the same rewrite.
- `CometShuffleExchangeExec.columnarShuffleSupports`: new helper that
guards the rewrite with the existing JVM columnar shuffle checks (Celeborn,
`columnarShuffleFailureReasons`). When it is false, the plan is left as is.
- `CometArrowStream.reconcileStreamSchema`: a column that is not a
`CometVector` now throws an `IllegalStateException` naming its class, instead
of a bare `ClassCastException`. No config or public API changes.
## How are these changes tested?
<!--
We typically require tests for all PRs in order to:
1. Prevent the code from being accidentally broken by subsequent changes
2. Serve as another way to document the expected behavior of the code
If tests are not included in your PR, please explain why (for example, are
they covered by existing tests)?
-->
New test in `EliminateRedundantTransitionsSuite` builds
`CometShuffleExchangeExec(CometNativeShuffle)` over
`RowToColumnarExec(rowChild)` and checks that:
- the rule returns a JVM columnar shuffle over `rowChild`,
- the rewritten plan executes and returns all rows,
- executing the original plan fails with the new error.
Without the rule change, the test fails on the first check. Without the
`reconcileStreamSchema` change, executing the original plan on Apache Spark 4.1
fails with the exception seen on EMR:
```
java.lang.ClassCastException: class
org.apache.spark.sql.execution.vectorized.OffHeapColumnVector cannot be cast to
class org.apache.comet.vector.CometVector
```
Ran locally (Spark 4.1 profile, JDK 17):
`EliminateRedundantTransitionsSuite`,
`RevertNativeForTransitionHeavyStagesSuite`, `CometNativeShuffleSuite`.
<details><summary>Local test output</summary>
```
- native shuffle over Spark's RowToColumnar moves to the JVM columnar
shuffle (594 milliseconds)
Tests: succeeded 128, failed 0, canceled 0, ignored 0, pending 0
BUILD SUCCESS
```
</details>
--
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]