You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@datafusion.apache.org by "andygrove (via GitHub)" <gi...@apache.org> on 2025/01/01 18:23:37 UTC
[PR] perf: Choose better shuffle [datafusion-comet]
andygrove opened a new pull request, #1209:
URL: https://github.com/apache/datafusion-comet/pull/1209
## 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 https://github.com/apache/datafusion-comet/issues/1208
## 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.
-->
## 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.
-->
## 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)?
-->
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] perf: Improve query planning to more reliably fall back to columnar shuffle when native shuffle is not supported [datafusion-comet]
Posted by "andygrove (via GitHub)" <gi...@apache.org>.
andygrove merged PR #1209:
URL: https://github.com/apache/datafusion-comet/pull/1209
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] perf: Improve query planning to more reliably fall back to columnar shuffle when native shuffle is not supported [datafusion-comet]
Posted by "andygrove (via GitHub)" <gi...@apache.org>.
andygrove commented on code in PR #1209:
URL: https://github.com/apache/datafusion-comet/pull/1209#discussion_r1900473667
##########
spark/src/main/scala/org/apache/comet/CometSparkSessionExtensions.scala:
##########
@@ -788,68 +788,82 @@ class CometSparkSessionExtensions
}
// Native shuffle for Comet operators
- case s: ShuffleExchangeExec
- if isCometShuffleEnabled(conf) &&
+ case s: ShuffleExchangeExec =>
+ val nativeShuffle: Option[SparkPlan] =
+ if (isCometShuffleEnabled(conf) &&
isCometNativeShuffleMode(conf) &&
- QueryPlanSerde.supportPartitioning(s.child.output, s.outputPartitioning)._1 =>
- logInfo("Comet extension enabled for Native Shuffle")
-
- val newOp = transform1(s)
- newOp match {
- case Some(nativeOp) =>
- // Switch to use Decimal128 regardless of precision, since Arrow native execution
- // doesn't support Decimal32 and Decimal64 yet.
- conf.setConfString(CometConf.COMET_USE_DECIMAL_128.key, "true")
- val cometOp = CometShuffleExchangeExec(s, shuffleType = CometNativeShuffle)
- CometSinkPlaceHolder(nativeOp, s, cometOp)
- case None =>
- s
- }
+ QueryPlanSerde.supportPartitioning(s.child.output, s.outputPartitioning)._1) {
+ val newOp = transform1(s)
+ newOp match {
+ case Some(nativeOp) =>
+ // Switch to use Decimal128 regardless of precision, since Arrow native execution
+ // doesn't support Decimal32 and Decimal64 yet.
+ conf.setConfString(CometConf.COMET_USE_DECIMAL_128.key, "true")
+ val cometOp = CometShuffleExchangeExec(s, shuffleType = CometNativeShuffle)
+ Some(CometSinkPlaceHolder(nativeOp, s, cometOp))
+ case None =>
+ None
+ }
+ } else {
+ None
+ }
- // Columnar shuffle for regular Spark operators (not Comet) and Comet operators
- // (if configured).
- // If the child of ShuffleExchangeExec is also a ShuffleExchangeExec, we should not
- // convert it to CometColumnarShuffle,
- case s: ShuffleExchangeExec
- if isCometShuffleEnabled(conf) && isCometJVMShuffleMode(conf) &&
Review Comment:
This part is triggered, but in the following code, `transform1(s)` returns `None` so we return the original shuffle.
```scala
val newOp = transform1(s)
newOp match {
case Some(nativeOp) =>
// Switch to use Decimal128 regardless of precision, since Arrow native execution
// doesn't support Decimal32 and Decimal64 yet.
conf.setConfString(CometConf.COMET_USE_DECIMAL_128.key, "true")
val cometOp = CometShuffleExchangeExec(s, shuffleType = CometNativeShuffle)
CometSinkPlaceHolder(nativeOp, s, cometOp)
case None =>
s
}
```
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] perf: Improve query planning to more reliably fall back to columnar shuffle when native shuffle is not supported [datafusion-comet]
Posted by "andygrove (via GitHub)" <gi...@apache.org>.
andygrove commented on PR #1209:
URL: https://github.com/apache/datafusion-comet/pull/1209#issuecomment-2578822397
Summary of Spark SQL test failures:
| Test | Failure |
|-|-|
| reverse preceding/following range between with aggregation | CometNativeException: Invalid argument error: Invalid arithmetic operation: Int32 - Int64 |
| SPARK-32038: NormalizeFloatingNumbers should work on distinct aggregate | results do not match (https://github.com/apache/datafusion-comet/issues/1238) |
| write null values | Accounted size went negative |
| window function: partition and order expressions | match error on Literal at QueryPlanSerde.scala:3158 |
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] perf: Improve query planning to more reliably fall back to columnar shuffle when native shuffle is not supported [datafusion-comet]
Posted by "andygrove (via GitHub)" <gi...@apache.org>.
andygrove commented on code in PR #1209:
URL: https://github.com/apache/datafusion-comet/pull/1209#discussion_r1909598881
##########
spark/src/test/scala/org/apache/spark/sql/CometTestBase.scala:
##########
@@ -78,6 +78,7 @@ abstract class CometTestBase
conf.set(CometConf.COMET_ENABLED.key, "true")
conf.set(CometConf.COMET_EXEC_ENABLED.key, "true")
conf.set(CometConf.COMET_EXEC_SHUFFLE_ENABLED.key, "true")
+ conf.set(CometConf.COMET_SHUFFLE_FALLBACK_TO_COLUMNAR.key, "true")
Review Comment:
The follow on issue for enabling it (actually removing the config) is https://github.com/apache/datafusion-comet/issues/1254
We need to fix the failures first: https://github.com/apache/datafusion-comet/issues/1256
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] perf: Improve query planning to more reliably fall back to columnar shuffle when native shuffle is not supported [datafusion-comet]
Posted by "andygrove (via GitHub)" <gi...@apache.org>.
andygrove commented on code in PR #1209:
URL: https://github.com/apache/datafusion-comet/pull/1209#discussion_r1908720790
##########
spark/src/main/scala/org/apache/comet/CometSparkSessionExtensions.scala:
##########
@@ -788,68 +788,82 @@ class CometSparkSessionExtensions
}
// Native shuffle for Comet operators
- case s: ShuffleExchangeExec
- if isCometShuffleEnabled(conf) &&
+ case s: ShuffleExchangeExec =>
+ val nativeShuffle: Option[SparkPlan] =
+ if (isCometShuffleEnabled(conf) &&
isCometNativeShuffleMode(conf) &&
- QueryPlanSerde.supportPartitioning(s.child.output, s.outputPartitioning)._1 =>
- logInfo("Comet extension enabled for Native Shuffle")
-
- val newOp = transform1(s)
- newOp match {
- case Some(nativeOp) =>
- // Switch to use Decimal128 regardless of precision, since Arrow native execution
- // doesn't support Decimal32 and Decimal64 yet.
- conf.setConfString(CometConf.COMET_USE_DECIMAL_128.key, "true")
- val cometOp = CometShuffleExchangeExec(s, shuffleType = CometNativeShuffle)
- CometSinkPlaceHolder(nativeOp, s, cometOp)
- case None =>
- s
- }
+ QueryPlanSerde.supportPartitioning(s.child.output, s.outputPartitioning)._1) {
+ val newOp = transform1(s)
+ newOp match {
+ case Some(nativeOp) =>
+ // Switch to use Decimal128 regardless of precision, since Arrow native execution
+ // doesn't support Decimal32 and Decimal64 yet.
+ conf.setConfString(CometConf.COMET_USE_DECIMAL_128.key, "true")
+ val cometOp = CometShuffleExchangeExec(s, shuffleType = CometNativeShuffle)
+ Some(CometSinkPlaceHolder(nativeOp, s, cometOp))
+ case None =>
+ None
+ }
+ } else {
+ None
+ }
- // Columnar shuffle for regular Spark operators (not Comet) and Comet operators
- // (if configured).
- // If the child of ShuffleExchangeExec is also a ShuffleExchangeExec, we should not
- // convert it to CometColumnarShuffle,
- case s: ShuffleExchangeExec
- if isCometShuffleEnabled(conf) && isCometJVMShuffleMode(conf) &&
Review Comment:
This is now explained in more detail in new issue https://github.com/apache/datafusion-comet/issues/1248
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] perf: Improve query planning to more reliably fall back to columnar shuffle when native shuffle is not supported [datafusion-comet]
Posted by "kazuyukitanimura (via GitHub)" <gi...@apache.org>.
kazuyukitanimura commented on code in PR #1209:
URL: https://github.com/apache/datafusion-comet/pull/1209#discussion_r1909581449
##########
spark/src/test/scala/org/apache/spark/sql/CometTestBase.scala:
##########
@@ -78,6 +78,7 @@ abstract class CometTestBase
conf.set(CometConf.COMET_ENABLED.key, "true")
conf.set(CometConf.COMET_EXEC_ENABLED.key, "true")
conf.set(CometConf.COMET_EXEC_SHUFFLE_ENABLED.key, "true")
+ conf.set(CometConf.COMET_SHUFFLE_FALLBACK_TO_COLUMNAR.key, "true")
Review Comment:
Do we have a plan to enable this in Spark tests? I guess we need to fix some bugs first, but might be a good idea to file an issue ticket...
##########
spark/src/main/scala/org/apache/comet/CometSparkSessionExtensions.scala:
##########
@@ -788,68 +788,93 @@ class CometSparkSessionExtensions
}
// Native shuffle for Comet operators
- case s: ShuffleExchangeExec
- if isCometShuffleEnabled(conf) &&
- isCometNativeShuffleMode(conf) &&
- QueryPlanSerde.supportPartitioning(s.child.output, s.outputPartitioning)._1 =>
- logInfo("Comet extension enabled for Native Shuffle")
+ case s: ShuffleExchangeExec =>
+ val nativePrecondition = isCometShuffleEnabled(conf) &&
+ isCometNativeShuffleMode(conf) &&
+ QueryPlanSerde.supportPartitioning(s.child.output, s.outputPartitioning)._1
- val newOp = transform1(s)
- newOp match {
- case Some(nativeOp) =>
- // Switch to use Decimal128 regardless of precision, since Arrow native execution
- // doesn't support Decimal32 and Decimal64 yet.
- conf.setConfString(CometConf.COMET_USE_DECIMAL_128.key, "true")
- val cometOp = CometShuffleExchangeExec(s, shuffleType = CometNativeShuffle)
- CometSinkPlaceHolder(nativeOp, s, cometOp)
- case None =>
- s
- }
+ val nativeShuffle: Option[SparkPlan] =
+ if (nativePrecondition) {
+ val newOp = transform1(s)
+ newOp match {
+ case Some(nativeOp) =>
+ // Switch to use Decimal128 regardless of precision, since Arrow native execution
+ // doesn't support Decimal32 and Decimal64 yet.
+ conf.setConfString(CometConf.COMET_USE_DECIMAL_128.key, "true")
+ val cometOp = CometShuffleExchangeExec(s, shuffleType = CometNativeShuffle)
+ Some(CometSinkPlaceHolder(nativeOp, s, cometOp))
+ case None =>
+ None
+ }
+ } else {
+ None
+ }
- // Columnar shuffle for regular Spark operators (not Comet) and Comet operators
- // (if configured).
- // If the child of ShuffleExchangeExec is also a ShuffleExchangeExec, we should not
- // convert it to CometColumnarShuffle,
- case s: ShuffleExchangeExec
- if isCometShuffleEnabled(conf) && isCometJVMShuffleMode(conf) &&
+ // this is a temporary workaround because some Spark SQL tests fail
+ // when we enable COMET_SHUFFLE_FALLBACK_TO_COLUMNAR due to valid bugs
+ // that we had not previously seen
+ val tryColumnarNext =
+ !nativePrecondition || (nativePrecondition && nativeShuffle.isEmpty &&
+ COMET_SHUFFLE_FALLBACK_TO_COLUMNAR.get(conf))
Review Comment:
nit: this can be shorter
```
val tryColumnarNext =
!nativePrecondition || (nativeShuffle.isEmpty && COMET_SHUFFLE_FALLBACK_TO_COLUMNAR.get(conf))
```
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] perf: Improve query planning to more reliably fall back to columnar shuffle when native shuffle is not supported [datafusion-comet]
Posted by "viirya (via GitHub)" <gi...@apache.org>.
viirya commented on code in PR #1209:
URL: https://github.com/apache/datafusion-comet/pull/1209#discussion_r1900464627
##########
spark/src/main/scala/org/apache/comet/CometSparkSessionExtensions.scala:
##########
@@ -788,68 +788,82 @@ class CometSparkSessionExtensions
}
// Native shuffle for Comet operators
- case s: ShuffleExchangeExec
- if isCometShuffleEnabled(conf) &&
+ case s: ShuffleExchangeExec =>
+ val nativeShuffle: Option[SparkPlan] =
+ if (isCometShuffleEnabled(conf) &&
isCometNativeShuffleMode(conf) &&
- QueryPlanSerde.supportPartitioning(s.child.output, s.outputPartitioning)._1 =>
- logInfo("Comet extension enabled for Native Shuffle")
-
- val newOp = transform1(s)
- newOp match {
- case Some(nativeOp) =>
- // Switch to use Decimal128 regardless of precision, since Arrow native execution
- // doesn't support Decimal32 and Decimal64 yet.
- conf.setConfString(CometConf.COMET_USE_DECIMAL_128.key, "true")
- val cometOp = CometShuffleExchangeExec(s, shuffleType = CometNativeShuffle)
- CometSinkPlaceHolder(nativeOp, s, cometOp)
- case None =>
- s
- }
+ QueryPlanSerde.supportPartitioning(s.child.output, s.outputPartitioning)._1) {
+ val newOp = transform1(s)
+ newOp match {
+ case Some(nativeOp) =>
+ // Switch to use Decimal128 regardless of precision, since Arrow native execution
+ // doesn't support Decimal32 and Decimal64 yet.
+ conf.setConfString(CometConf.COMET_USE_DECIMAL_128.key, "true")
+ val cometOp = CometShuffleExchangeExec(s, shuffleType = CometNativeShuffle)
+ Some(CometSinkPlaceHolder(nativeOp, s, cometOp))
+ case None =>
+ None
+ }
+ } else {
+ None
+ }
- // Columnar shuffle for regular Spark operators (not Comet) and Comet operators
- // (if configured).
- // If the child of ShuffleExchangeExec is also a ShuffleExchangeExec, we should not
- // convert it to CometColumnarShuffle,
- case s: ShuffleExchangeExec
- if isCometShuffleEnabled(conf) && isCometJVMShuffleMode(conf) &&
Review Comment:
Hmm, if it is auto mode, why this is not triggered?
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] perf: Improve query planning to more reliably fall back to columnar shuffle when native shuffle is not supported [datafusion-comet]
Posted by "andygrove (via GitHub)" <gi...@apache.org>.
andygrove commented on PR #1209:
URL: https://github.com/apache/datafusion-comet/pull/1209#issuecomment-2581472592
Thanks for the reviews @viirya and @kazuyukitanimura
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] perf: Improve query planning to more reliably fall back to columnar shuffle when native shuffle is not supported [datafusion-comet]
Posted by "andygrove (via GitHub)" <gi...@apache.org>.
andygrove commented on PR #1209:
URL: https://github.com/apache/datafusion-comet/pull/1209#issuecomment-2581116828
Thanks for the review @viirya. @kazuyukitanimura @parthchandra did you also want to review?
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org