-
Notifications
You must be signed in to change notification settings - Fork 567
[GLUTEN-11251] Fix incorrect whole stage id in WholeStageTransformerExec #11252
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
f8fa7c2
fix
marin-ma 0e36deb
fix transformStageId
marin-ma 38ee752
fix
marin-ma 9c258bc
fix
marin-ma 38fa5a4
fix
marin-ma 69c07a6
add cache
marin-ma d59ab66
fix
marin-ma 38b9b3b
update
marin-ma f36ea4a
update
marin-ma 26eac7d
address comments
marin-ma 33ed32f
fix ras
marin-ma 1bf8e88
spark41
marin-ma ff350e2
address comments
marin-ma File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
76 changes: 76 additions & 0 deletions
76
...en-substrait/src/main/scala/org/apache/spark/sql/execution/GenerateTransformStageId.scala
This file contains hidden or 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,76 @@ | ||
| /* | ||
| * 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.gluten.exception.GlutenException | ||
| import org.apache.gluten.execution.WholeStageTransformer | ||
| import org.apache.gluten.sql.shims.SparkShimLoader | ||
|
|
||
| import org.apache.spark.sql.catalyst.rules.Rule | ||
| import org.apache.spark.sql.execution.adaptive.{AdaptiveSparkPlanExec, AdaptiveSparkPlanHelper, BroadcastQueryStageExec, ShuffleQueryStageExec} | ||
| import org.apache.spark.sql.execution.exchange.{BroadcastExchangeLike, ReusedExchangeExec, ShuffleExchangeLike} | ||
|
|
||
| import java.util | ||
| import java.util.Collections.newSetFromMap | ||
| import java.util.concurrent.atomic.AtomicInteger | ||
|
|
||
| /** | ||
| * Generate `transformStageId` for `WholeStageTransformerExec`. This rule updates the whole plan | ||
| * tree with * incremental and unique transform stage id before the final execution. | ||
| * | ||
| * In Spark, the whole stage id is generated by incrementing a global counter. In Gluten, it's not | ||
| * possible to use global counter for id generation, especially in the case of AQE. | ||
| */ | ||
| case class GenerateTransformStageId() extends Rule[SparkPlan] with AdaptiveSparkPlanHelper { | ||
| private val transformStageCounter: AtomicInteger = new AtomicInteger(0) | ||
|
|
||
| private val wholeStageTransformerCache = | ||
| newSetFromMap[WholeStageTransformer](new util.IdentityHashMap()) | ||
|
|
||
| def apply(plan: SparkPlan): SparkPlan = { | ||
| updateStageId(plan) | ||
| plan | ||
| } | ||
|
|
||
| private def updateStageId(plan: SparkPlan): Unit = { | ||
| plan match { | ||
| case b: BroadcastQueryStageExec => | ||
| b.plan match { | ||
| case b: BroadcastExchangeLike => updateStageId(b) | ||
| case _: ReusedExchangeExec => | ||
| case _ => | ||
| throw new GlutenException(s"wrong plan for broadcast stage:\n ${plan.treeString}") | ||
| } | ||
| case s: ShuffleQueryStageExec => | ||
| s.plan match { | ||
| case s: ShuffleExchangeLike => updateStageId(s) | ||
| case _: ReusedExchangeExec => | ||
| case _ => | ||
| throw new GlutenException(s"wrong plan for shuffle stage:\n ${plan.treeString}") | ||
| } | ||
| case aqe: AdaptiveSparkPlanExec if SparkShimLoader.getSparkShims.isFinalAdaptivePlan(aqe) => | ||
| updateStageId(stripAQEPlan(aqe)) | ||
| case wst: WholeStageTransformer if !wholeStageTransformerCache.contains(wst) => | ||
| updateStageId(wst.child) | ||
| wst.transformStageId = transformStageCounter.incrementAndGet() | ||
| wholeStageTransformerCache.add(wst) | ||
| case plan => | ||
| plan.subqueries.foreach(updateStageId) | ||
| plan.children.foreach(updateStageId) | ||
| } | ||
| } | ||
| } |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why changing to
var?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When AQE is on,
transformStageIdalways starts at 0 within each query stage. In this casetransformStageIdis not globally unique within the whole plan tree. After all query stages have been executed, theRegenerateTransformStageIdrule traverses the whole plan tree and updates this value incrementally to a unique id.