-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-32347][SQL] Hint in CTE should be resolved in Hints batch rule #29156
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,9 +20,8 @@ package org.apache.spark.sql.catalyst.analysis | |
| import java.util.Locale | ||
|
|
||
| import scala.collection.mutable | ||
|
|
||
| import org.apache.spark.sql.AnalysisException | ||
| import org.apache.spark.sql.catalyst.expressions.{Ascending, Expression, IntegerLiteral, SortOrder} | ||
| import org.apache.spark.sql.catalyst.expressions.{Ascending, Expression, IntegerLiteral, SortOrder, SubqueryExpression} | ||
| import org.apache.spark.sql.catalyst.plans.logical._ | ||
| import org.apache.spark.sql.catalyst.rules.Rule | ||
| import org.apache.spark.sql.catalyst.trees.CurrentOrigin | ||
|
|
@@ -165,6 +164,24 @@ object ResolveHints { | |
| hintErrorHandler.hintRelationsNotFound(h.name, h.parameters, unmatchedIdents) | ||
| applied | ||
| } | ||
| case With(child, relations) => resolveCTEHint(child, | ||
| relations.foldLeft(Seq.empty[(String, LogicalPlan)]) { | ||
| case (resolved, (name, relation)) => | ||
| resolved :+ name -> apply(resolveCTEHint(relation, resolved)) | ||
| }) | ||
| } | ||
|
|
||
| def resolveCTEHint(plan: LogicalPlan, cteRelations: Seq[(String, LogicalPlan)]): LogicalPlan = { | ||
| plan resolveOperatorsDown { | ||
| case u: UnresolvedRelation => | ||
| cteRelations.find(x => resolver(x._1, u.tableName)).map(_._2).getOrElse(u) | ||
|
Comment on lines
+177
to
+178
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This branch will occur
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Have you looked at #29062 ? Seems easier to just run CTE substitution in the very beginning.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, |
||
| case other => | ||
| // This cannot be done in ResolveSubquery because ResolveSubquery does not know the CTE. | ||
| other transformExpressions { | ||
| case e: SubqueryExpression => | ||
| e.withNewPlan(resolveCTEHint(e.plan, cteRelations)) | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2558,6 +2558,13 @@ abstract class SQLQuerySuiteBase extends QueryTest with SQLTestUtils with TestHi | |
| } | ||
| } | ||
| } | ||
|
|
||
| test("SPARK-32347: cte hint regression") { | ||
| withTempView("t") { | ||
| sql("create temporary view t as select 1 as id") | ||
| sql("with cte as (select /*+ BROADCAST(id) */ id from t) select id from cte") | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just in case, could you check that the hist is correctly applied?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thank you, I need to check the hist, seems something wrong with the patch. |
||
| } | ||
| } | ||
| } | ||
|
|
||
| @SlowHiveTest | ||
|
|
||
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.
This patch looks like it is specifically designed to fix
Withcomparing to #29062. I am open to more comments.