Skip to content

Commit 0c54798

Browse files
committed
address comments
1 parent 29aaaaf commit 0c54798

File tree

1 file changed

+10
-12
lines changed
  • sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis

1 file changed

+10
-12
lines changed

sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/Analyzer.scala

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ class Analyzer(
4646
val resolver = if (caseSensitive) caseSensitiveResolution else caseInsensitiveResolution
4747

4848
val fixedPoint = FixedPoint(maxIterations)
49-
49+
5050
/**
5151
* Override to provide additional rules for the "Resolution" batch.
5252
*/
@@ -72,16 +72,12 @@ class Analyzer(
7272
)
7373

7474
/**
75-
* Substitute CTE definitions
75+
* Substitute child plan with cte definitions
7676
*/
7777
object CTESubstitution extends Rule[LogicalPlan] {
78-
def apply(plan: LogicalPlan): LogicalPlan = {
79-
val (realPlan, cteRelations) = plan match {
80-
case With(child, relations) =>
81-
(child, relations)
82-
case other => (other, Map.empty[String, LogicalPlan])
83-
}
84-
substituteCTE(realPlan, cteRelations)
78+
def apply(plan: LogicalPlan): LogicalPlan = plan match {
79+
case With(child, relations) => substituteCTE(child, relations)
80+
case other => other
8581
}
8682

8783
def substituteCTE(plan: LogicalPlan, cteRelations: Map[String, LogicalPlan]): LogicalPlan = {
@@ -91,9 +87,11 @@ class Analyzer(
9187
// hive will use the table in database, not the CTE one.
9288
// Taking into account the reasonableness and the implementation complexity,
9389
// here use the CTE definition first, check table name only and ignore database name
94-
val relation = cteRelations.get(u.tableIdentifier.last)
95-
.map(relation => u.alias.map(Subquery(_, relation)).getOrElse(relation))
96-
.getOrElse(u)
90+
val substituted = cteRelations.get(u.tableIdentifier.last).map { relation =>
91+
val withAlias = u.alias.map(Subquery(_, relation))
92+
withAlias.getOrElse(relation)
93+
}
94+
substituted.getOrElse(u)
9795
i.copy(table = relation)
9896
case u : UnresolvedRelation =>
9997
cteRelations.get(u.tableIdentifier.last)

0 commit comments

Comments
 (0)