Skip to content

Commit

Permalink
[SPARK-32237][SQL][3.0] Resolve hint in CTE
Browse files Browse the repository at this point in the history
  • Loading branch information
LantaoJin committed Jul 23, 2020
1 parent ad9e7a2 commit b5be044
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -200,16 +200,16 @@ class Analyzer(
val postHocResolutionRules: Seq[Rule[LogicalPlan]] = Nil

lazy val batches: Seq[Batch] = Seq(
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)),
Batch("Hints", fixedPoint,
new ResolveHints.ResolveJoinStrategyHints(conf),
new ResolveHints.ResolveCoalesceHints(conf)),
Batch("Simple Sanity Check", Once,
LookupFunctions),
Batch("Resolution", fixedPoint,
ResolveTableValuedFunctions ::
ResolveNamespace(catalogManager) ::
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import org.apache.log4j.Level
import org.scalatest.Matchers

import org.apache.spark.api.python.PythonEvalType
import org.apache.spark.sql.catalyst.TableIdentifier
import org.apache.spark.sql.catalyst.{AliasIdentifier, TableIdentifier}
import org.apache.spark.sql.catalyst.catalog.{CatalogStorageFormat, CatalogTable, CatalogTableType, InMemoryCatalog, SessionCatalog}
import org.apache.spark.sql.catalyst.dsl.expressions._
import org.apache.spark.sql.catalyst.dsl.plans._
Expand Down Expand Up @@ -879,4 +879,27 @@ class AnalysisSuite extends AnalysisTest with Matchers {
Seq("Intersect can only be performed on tables with the compatible column types. " +
"timestamp <> double at the second column of the second table"))
}

test("SPARK-32237: Hint in CTE") {
val plan = With(
Project(
Seq(UnresolvedAttribute("cte.a")),
UnresolvedRelation(TableIdentifier("cte"))
),
Seq(
(
"cte",
SubqueryAlias(
AliasIdentifier("cte"),
UnresolvedHint(
"REPARTITION",
Seq(Literal(3)),
Project(testRelation.output, testRelation)
)
)
)
)
)
assertAnalysisSuccess(plan)
}
}
12 changes: 12 additions & 0 deletions sql/core/src/test/scala/org/apache/spark/sql/SQLQuerySuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3467,6 +3467,18 @@ class SQLQuerySuite extends QueryTest with SharedSparkSession with AdaptiveSpark
|""".stripMargin), Row(1))
}
}

test("SPARK-32237: Hint in CTE") {
withTable("t") {
sql("CREATE TABLE t USING PARQUET AS SELECT 1 AS id")
checkAnswer(
sql(s"""
|WITH cte AS (SELECT /*+ REPARTITION(3) */ * FROM t)
|SELECT * FROM cte
""".stripMargin),
Row(1) :: Nil)
}
}
}

case class Foo(bar: Option[String])

0 comments on commit b5be044

Please sign in to comment.