Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -200,18 +200,18 @@ class Analyzer(
val postHocResolutionRules: Seq[Rule[LogicalPlan]] = Nil

lazy val batches: Seq[Batch] = Seq(
Batch("Substitution", fixedPoint,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why we have to execute the batch Substitution before the batch ResolveHints? What is the root cause? I am unable to tell it from either PR description or the code comments. Could any of you explain it?

cc @maryannxue

@LantaoJin LantaoJin Aug 5, 2020

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know which PR causes this regression problem since there is a big gap between 2.4 and 3.0 about CTE. I am not familiar with this part.
I fixed this by debuging. In 3.0, I found only the child of CTE could enter into the rule of ResolveCoalesceHints. For the above test case:

CTE [cte]
:  +- 'SubqueryAlias `cte`
:     +- 'UnresolvedHint REPARTITION, [3]
:        +- 'Project [*]
:           +- 'UnresolvedRelation `t`
+- 'Project [*]
   +- 'UnresolvedRelation `cte`

Only this child Project branch could enter into the rule of ResolveCoalesceHints

+- 'Project [*]
   +- 'UnresolvedRelation `cte`

CTESubstitution,
WindowsSubstitution,
EliminateUnions,
new SubstituteUnresolvedOrdinals(conf)),

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I checked the order of analysis rules in branch-2.4. Substitution batch is after Hints too, like branch-3.0. Is there any change causing this issue?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's hard to find which change causing it for me since 2.4 and 3.0 have many differences that I don't know.

Batch("Disable Hints", Once,
new ResolveHints.DisableHints(conf)),
Batch("Hints", fixedPoint,
new ResolveHints.ResolveJoinStrategyHints(conf),
new ResolveHints.ResolveCoalesceHints(conf)),
Batch("Simple Sanity Check", Once,
LookupFunctions),
Batch("Substitution", fixedPoint,
CTESubstitution,
WindowsSubstitution,
EliminateUnions,
new SubstituteUnresolvedOrdinals(conf)),
Comment on lines 202 to -214

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems cool : )

Batch("Resolution", fixedPoint,
ResolveTableValuedFunctions ::
ResolveNamespace(catalogManager) ::
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -756,6 +756,19 @@ class DataSourceV2SQLSuite
}
}

test("SPARK-32237: Hint in CTE") {
Comment thread
LantaoJin marked this conversation as resolved.
Outdated
val t1 = "testcat.ns1.ns2.tbl"
Comment thread
LantaoJin marked this conversation as resolved.
Outdated
withTable(t1) {
sql(s"CREATE TABLE $t1 USING foo AS SELECT id, data FROM source")
checkAnswer(
sql(s"""
|WITH cte AS (SELECT /*+ REPARTITION(3) */ * FROM $t1)
|SELECT * FROM cte
""".stripMargin),
spark.table("source"))
}
}

test("Relation: view text") {
val t1 = "testcat.ns1.ns2.tbl"
withTable(t1) {
Expand Down