forked from apache/spark
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[SPARK-34168][SQL] Support DPP in AQE when the join is Broadcast hash…
… join at the beginning This PR is to enable AQE and DPP when the join is broadcast hash join at the beginning, which can benefit the performance improvement from DPP and AQE at the same time. This PR will make use of the result of build side and then insert the DPP filter into the probe side. Improve performance No adding new ut Closes apache#31258 from JkSelf/supportDPP1. Authored-by: jiake <ke.a.jia@intel.com> Signed-off-by: Wenchen Fan <wenchen@databricks.com>
- Loading branch information
Showing
11 changed files
with
198 additions
and
38 deletions.
There are no files selected for viewing
42 changes: 42 additions & 0 deletions
42
sql/core/src/main/scala/org/apache/spark/sql/execution/SubqueryAdaptiveBroadcastExec.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,42 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You 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 org.apache.spark.sql.execution | ||
|
||
import org.apache.spark.rdd.RDD | ||
import org.apache.spark.sql.catalyst.InternalRow | ||
import org.apache.spark.sql.catalyst.expressions._ | ||
|
||
/** | ||
* Similar to [[SubqueryBroadcastExec]], this node is used to store the | ||
* initial physical plan of DPP subquery filters when enabling both AQE and DPP. | ||
* It is intermediate physical plan and not executable. | ||
* After the build side is executed, this node will be replaced with the | ||
* [[SubqueryBroadcastExec]] and the child will be optimized with the ReusedExchange | ||
* from the build side. | ||
*/ | ||
case class SubqueryAdaptiveBroadcastExec( | ||
name: String, | ||
index: Int, | ||
buildKeys: Seq[Expression], | ||
child: SparkPlan) extends BaseSubqueryExec with UnaryExecNode { | ||
|
||
protected override def doExecute(): RDD[InternalRow] = { | ||
throw new UnsupportedOperationException( | ||
"SubqueryAdaptiveBroadcastExec does not support the execute() code path.") | ||
} | ||
} |
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
59 changes: 59 additions & 0 deletions
59
...ain/scala/org/apache/spark/sql/execution/adaptive/PlanAdaptiveDynamicPruningFilters.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,59 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You 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 org.apache.spark.sql.execution.adaptive | ||
|
||
import scala.collection.concurrent.TrieMap | ||
|
||
import org.apache.spark.sql.catalyst.expressions.{BindReferences, DynamicPruningExpression, Literal} | ||
import org.apache.spark.sql.catalyst.rules.Rule | ||
import org.apache.spark.sql.execution._ | ||
import org.apache.spark.sql.execution.exchange.BroadcastExchangeExec | ||
import org.apache.spark.sql.execution.joins.{HashedRelationBroadcastMode, HashJoin} | ||
|
||
/** | ||
* A rule to insert dynamic pruning predicates in order to reuse the results of broadcast. | ||
*/ | ||
case class PlanAdaptiveDynamicPruningFilters( | ||
stageCache: TrieMap[SparkPlan, QueryStageExec]) extends Rule[SparkPlan] { | ||
def apply(plan: SparkPlan): SparkPlan = { | ||
if (!conf.dynamicPartitionPruningEnabled) { | ||
return plan | ||
} | ||
|
||
plan transformAllExpressions { | ||
case DynamicPruningExpression(InSubqueryExec( | ||
value, SubqueryAdaptiveBroadcastExec(name, index, buildKeys, | ||
adaptivePlan: AdaptiveSparkPlanExec), exprId, _)) => | ||
val packedKeys = BindReferences.bindReferences( | ||
HashJoin.rewriteKeyExpr(buildKeys), adaptivePlan.executedPlan.output) | ||
val mode = HashedRelationBroadcastMode(packedKeys) | ||
// plan a broadcast exchange of the build side of the join | ||
val exchange = BroadcastExchangeExec(mode, adaptivePlan.executedPlan) | ||
val existingStage = stageCache.get(exchange.canonicalized) | ||
if (existingStage.nonEmpty && conf.exchangeReuseEnabled) { | ||
val name = s"dynamicpruning#${exprId.id}" | ||
val reuseQueryStage = existingStage.get.newReuseInstance(0, exchange.output) | ||
val broadcastValues = | ||
SubqueryBroadcastExec(name, index, buildKeys, reuseQueryStage) | ||
DynamicPruningExpression(InSubqueryExec(value, broadcastValues, exprId)) | ||
} else { | ||
DynamicPruningExpression(Literal.TrueLiteral) | ||
} | ||
} | ||
} | ||
} |
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
Oops, something went wrong.