-
Notifications
You must be signed in to change notification settings - Fork 232
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix inconsistencies in AQE support for broadcast joins (#1042)
* Fix inconsistencies with AQE support for broadcast joins Signed-off-by: Andy Grove <andygrove@nvidia.com> * code cleanup and change test behavior for Spark 3.0.0 Signed-off-by: Andy Grove <andygrove@nvidia.com> * fix inconsistency Signed-off-by: Andy Grove <andygrove@nvidia.com> * fix test failure with Spark 3.1.0 Signed-off-by: Andy Grove <andygrove@nvidia.com> * fix inconsistency Signed-off-by: Andy Grove <andygrove@nvidia.com> * fix imports Signed-off-by: Andy Grove <andygrove@nvidia.com> * fix regression Signed-off-by: Andy Grove <andygrove@nvidia.com> * tighten up rules Signed-off-by: Andy Grove <andygrove@nvidia.com> * Move GpuBroadcastJoinMeta to com.nvidia.spark.rapids package Signed-off-by: Andy Grove <andygrove@nvidia.com> * Move GpuBroadcastJoinMeta to com.nvidia.spark.rapids package Signed-off-by: Andy Grove <andygrove@nvidia.com>
- Loading branch information
Showing
10 changed files
with
162 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
sql-plugin/src/main/scala/com/nvidia/spark/rapids/GpuBroadcastJoinMeta.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/* | ||
* Copyright (c) 2020, NVIDIA CORPORATION. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.nvidia.spark.rapids | ||
|
||
import org.apache.spark.sql.execution.SparkPlan | ||
import org.apache.spark.sql.execution.adaptive.BroadcastQueryStageExec | ||
import org.apache.spark.sql.execution.exchange.ReusedExchangeExec | ||
import org.apache.spark.sql.rapids.execution.GpuBroadcastExchangeExecBase | ||
|
||
abstract class GpuBroadcastJoinMeta[INPUT <: SparkPlan](plan: INPUT, | ||
conf: RapidsConf, | ||
parent: Option[RapidsMeta[_, _, _]], | ||
rule: ConfKeysAndIncompat) | ||
extends SparkPlanMeta[INPUT](plan, conf, parent, rule) { | ||
|
||
def canBuildSideBeReplaced(buildSide: SparkPlanMeta[_]): Boolean = { | ||
buildSide.wrapped match { | ||
case BroadcastQueryStageExec(_, _: GpuBroadcastExchangeExecBase) => true | ||
case BroadcastQueryStageExec(_, reused: ReusedExchangeExec) => | ||
reused.child.isInstanceOf[GpuBroadcastExchangeExecBase] | ||
case reused: ReusedExchangeExec => reused.child.isInstanceOf[GpuBroadcastExchangeExecBase] | ||
case _: GpuBroadcastExchangeExecBase => true | ||
case _ => buildSide.canThisBeReplaced | ||
} | ||
} | ||
|
||
def verifyBuildSideWasReplaced(buildSide: SparkPlan): Unit = { | ||
val buildSideOnGpu = buildSide match { | ||
case BroadcastQueryStageExec(_, _: GpuBroadcastExchangeExecBase) => true | ||
case BroadcastQueryStageExec(_, reused: ReusedExchangeExec) => | ||
reused.child.isInstanceOf[GpuBroadcastExchangeExecBase] | ||
case reused: ReusedExchangeExec => reused.child.isInstanceOf[GpuBroadcastExchangeExecBase] | ||
case _: GpuBroadcastExchangeExecBase => true | ||
case _ => false | ||
} | ||
if (!buildSideOnGpu) { | ||
throw new IllegalStateException(s"the broadcast must be on the GPU too") | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
tests/src/test/scala/com/nvidia/spark/rapids/BroadcastNestedLoopJoinSuite.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
/* | ||
* Copyright (c) 2020, NVIDIA CORPORATION. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.nvidia.spark.rapids | ||
|
||
import com.nvidia.spark.rapids.TestUtils.findOperators | ||
|
||
import org.apache.spark.SparkConf | ||
import org.apache.spark.sql.functions.broadcast | ||
import org.apache.spark.sql.internal.SQLConf | ||
|
||
class BroadcastNestedLoopJoinSuite extends SparkQueryCompareTestSuite { | ||
|
||
test("BroadcastNestedLoopJoinExec AQE off") { | ||
val conf = new SparkConf() | ||
.set("spark.rapids.sql.exec.BroadcastNestedLoopJoinExec", "true") | ||
.set(SQLConf.ADAPTIVE_EXECUTION_ENABLED.key, "false") | ||
|
||
withGpuSparkSession(spark => { | ||
val df1 = longsDf(spark).repartition(2) | ||
val df2 = nonZeroLongsDf(spark).repartition(2) | ||
val df3 = df1.crossJoin(broadcast(df2)) | ||
df3.collect() | ||
val plan = df3.queryExecution.executedPlan | ||
|
||
val nljCount = findOperators(plan, ShimLoader.getSparkShims.isGpuBroadcastNestedLoopJoin) | ||
assert(nljCount.size === 1) | ||
}, conf) | ||
} | ||
|
||
test("BroadcastNestedLoopJoinExec AQE on") { | ||
val conf = new SparkConf() | ||
.set("spark.rapids.sql.exec.BroadcastNestedLoopJoinExec", "true") | ||
.set(SQLConf.ADAPTIVE_EXECUTION_ENABLED.key, "true") | ||
|
||
withGpuSparkSession(spark => { | ||
val df1 = longsDf(spark).repartition(2) | ||
val df2 = nonZeroLongsDf(spark).repartition(2) | ||
val df3 = df1.crossJoin(broadcast(df2)) | ||
df3.collect() | ||
val plan = df3.queryExecution.executedPlan | ||
|
||
val nljCount = findOperators(plan, ShimLoader.getSparkShims.isGpuBroadcastNestedLoopJoin) | ||
|
||
ShimLoader.getSparkShims.getSparkShimVersion match { | ||
case SparkShimVersion(3, 0, 0) => | ||
// we didn't start supporting GPU exchanges with AQE until 3.0.1 | ||
assert(nljCount.size === 0) | ||
case _ => | ||
assert(nljCount.size === 1) | ||
} | ||
|
||
}, conf) | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters