-
Notifications
You must be signed in to change notification settings - Fork 28.9k
[SPARK-46170][SQL] Support inject adaptive query post planner strategy rules in SparkSessionExtensions #44074
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
Conversation
|
cc @dongjoon-hyun @cloud-fan this pr is only for adding Adaptive Query Post Planner Strategy Rules part. |
dongjoon-hyun
left a comment
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.
Thank you for making a PR, @ulysses-you .
| type ColumnarRuleBuilder = SparkSession => ColumnarRule | ||
| type QueryStagePrepRuleBuilder = SparkSession => Rule[SparkPlan] | ||
| type QueryStageOptimizerRuleBuilder = SparkSession => Rule[SparkPlan] | ||
| type QueryPostPlannerStrategyBuilder = SparkSession => Rule[SparkPlan] |
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.
Shall we put this before type QueryStagePrepRuleBuilder because this rule is supposed to be used before queryStagePreparationRules?
| private[this] val queryStageOptimizerRuleBuilders = | ||
| mutable.Buffer.empty[QueryStageOptimizerRuleBuilder] | ||
| private[this] val queryPostPlannerStrategyRuleBuilders = | ||
| mutable.Buffer.empty[QueryPostPlannerStrategyBuilder] |
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.
Ditto. Shall we put this before private[this] val queryStagePrepRuleBuilders?
| session: SparkSession): Seq[Rule[SparkPlan]] = { | ||
| queryPostPlannerStrategyRuleBuilders.map(_.apply(session)).toSeq | ||
| } | ||
|
|
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.
ditto. Shall we put this before private[sql] def buildQueryStagePrepRules?
| def injectQueryPostPlannerStrategyRule(builder: QueryPostPlannerStrategyBuilder): Unit = { | ||
| queryPostPlannerStrategyRuleBuilders += builder | ||
| } | ||
|
|
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.
ditto. Shall we put this before def injectQueryStagePrepRule?
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.
+1, it looks reasonable to me. I left a few minor comments. Thank you, @ulysses-you .
Also, cc @sunchao , too
| withSession(extensions) { session => | ||
| assert(session.sessionState.adaptiveRulesHolder.queryPostPlannerStrategyRules | ||
| .contains(MyQueryPostPlannerStrategyRule)) | ||
| import session.sqlContext.implicits._ |
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.
how about just use session.implicits._?
| import session.sqlContext.implicits._ | ||
| withSQLConf(SQLConf.SHUFFLE_PARTITIONS.key -> "3", | ||
| SQLConf.COALESCE_PARTITIONS_ENABLED.key -> "false") { | ||
| val input = Seq((10), (20), (10)).toDF("c1") |
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 is it necessary to add parentheses to each element? for readability?
| SQLConf.COALESCE_PARTITIONS_ENABLED.key -> "false") { | ||
| val input = Seq((10), (20), (10)).toDF("c1") | ||
| val df = input.groupBy("c1").count() | ||
| df.collect() |
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.
I tried it, and even if df.collect() is not executed, this test case can still pass. So, is it necessary?
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.
it is used to make sure we are checking the final plan
| df.collect() | ||
| assert(df.rdd.partitions.length == 1) | ||
| assert(find(df.queryExecution.executedPlan) { | ||
| case s: ShuffleExchangeExec if s.outputPartitioning == SinglePartition => true |
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.
How about case s: ShuffleExchangeExec => s.outputPartitioning == SinglePartition
Additionally, a personal opinion unrelated to this pr: If there is an exists function in AdaptiveSparkPlanHelper, would this assertion be simpler to write?
| case s: ShuffleExchangeExec if s.outputPartitioning == SinglePartition => true | ||
| case _ => false | ||
| }.isDefined) | ||
| assert(find(df.queryExecution.executedPlan) { |
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.
Seems using collectFirst could eliminate the case _ => false branch?
|
thank you @dongjoon-hyun @LuciferYang , addressed comments |
|
thanks for review, merged to master. |
…y rules in SparkSessionExtensions ### What changes were proposed in this pull request? This pr adds a new extension entrance `queryPostPlannerStrategyRules` in `SparkSessionExtensions`. It will be applied between plannerStrategy and queryStagePrepRules in AQE, so it can get the whole plan before injecting exchanges. ### Why are the changes needed? a part of apache#44013 ### Does this PR introduce _any_ user-facing change? no, only for develop ### How was this patch tested? add test ### Was this patch authored or co-authored using generative AI tooling? no Closes apache#44074 from ulysses-you/post-planner. Authored-by: ulysses-you <[email protected]> Signed-off-by: youxiduo <[email protected]>
…rategy rules in SparkSessionExtensions This pr is backport #44074 for branch-3.5 since 3.5 is a lts version ### What changes were proposed in this pull request? This pr adds a new extension entrance `queryPostPlannerStrategyRules` in `SparkSessionExtensions`. It will be applied between plannerStrategy and queryStagePrepRules in AQE, so it can get the whole plan before injecting exchanges. ### Why are the changes needed? 3.5 is a lts version ### Does this PR introduce _any_ user-facing change? no, only for develop ### How was this patch tested? add test ### Was this patch authored or co-authored using generative AI tooling? no Closes #44074 from ulysses-you/post-planner. Authored-by: ulysses-you <ulyssesyou18gmail.com> Closes #45037 from ulysses-you/SPARK-46170. Authored-by: ulysses-you <[email protected]> Signed-off-by: Kent Yao <[email protected]>
…rategy rules in SparkSessionExtensions (apache#366) This pr is backport apache#44074 for branch-3.5 since 3.5 is a lts version ### What changes were proposed in this pull request? This pr adds a new extension entrance `queryPostPlannerStrategyRules` in `SparkSessionExtensions`. It will be applied between plannerStrategy and queryStagePrepRules in AQE, so it can get the whole plan before injecting exchanges. ### Why are the changes needed? 3.5 is a lts version ### Does this PR introduce _any_ user-facing change? no, only for develop ### How was this patch tested? add test ### Was this patch authored or co-authored using generative AI tooling? no Closes apache#44074 from ulysses-you/post-planner. Authored-by: ulysses-you <ulyssesyou18gmail.com> Closes apache#45037 from ulysses-you/SPARK-46170. Authored-by: ulysses-you <[email protected]> Signed-off-by: Kent Yao <[email protected]> Co-authored-by: ulysses-you <[email protected]>
What changes were proposed in this pull request?
This pr adds a new extension entrance
queryPostPlannerStrategyRulesinSparkSessionExtensions. It will be applied between plannerStrategy and queryStagePrepRules in AQE, so it can get the whole plan before injecting exchanges.Why are the changes needed?
a part of #44013
Does this PR introduce any user-facing change?
no, only for develop
How was this patch tested?
add test
Was this patch authored or co-authored using generative AI tooling?
no