Skip to content

Commit 597d49f

Browse files
vladimirg-dbcloud-fan
authored andcommitted
[SPARK-52447][SQL] Move GetViewColumnByNameAndOrdinal normalization to SessionCatalogSuite
### What changes were proposed in this pull request? Move `GetViewColumnByNameAndOrdinal` normalization to `SessionCatalogSuite`. This normalization is not universal and is only relevant for that suite. ### Why are the changes needed? To avoid dropping coverage when comparing single-pass and fixed-point Analyzer logical plans. ### Does this PR introduce _any_ user-facing change? Test-only change. ### How was this patch tested? Updated `SessionCatalogSuite`. ### Was this patch authored or co-authored using generative AI tooling? No. Closes #51155 from vladimirg-db/vladimir-golubev_data/move-get-view-column-by-name-and-ordinal-normalization-to-a-separate-test. Authored-by: Vladimir Golubev <[email protected]> Signed-off-by: Wenchen Fan <[email protected]>
1 parent bf92373 commit 597d49f

File tree

2 files changed

+21
-18
lines changed

2 files changed

+21
-18
lines changed

sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/plans/NormalizePlan.scala

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import java.util.HashMap
2121

2222
import org.apache.spark.sql.catalyst.analysis.{
2323
DeduplicateRelations,
24-
GetViewColumnByNameAndOrdinal,
2524
NormalizeableRelation
2625
}
2726
import org.apache.spark.sql.catalyst.expressions._
@@ -160,14 +159,12 @@ object NormalizePlan extends PredicateHelper {
160159
innerProject.child
161160
)
162161
aggregate.copy(child = newInnerProject)
163-
case Project(outerProjectList, innerProject: Project) =>
162+
case project @ Project(_, innerProject: Project) =>
164163
val newInnerProject = Project(
165164
innerProject.projectList.sortBy(_.name),
166165
innerProject.child
167166
)
168-
Project(normalizeProjectList(outerProjectList), newInnerProject)
169-
case Project(projectList, child) =>
170-
Project(normalizeProjectList(projectList), child)
167+
project.copy(child = newInnerProject)
171168
case c: KeepAnalyzedQuery => c.storeAnalyzedQuery()
172169
case localRelation: LocalRelation if !localRelation.data.isEmpty =>
173170
/**
@@ -203,16 +200,6 @@ object NormalizePlan extends PredicateHelper {
203200
case LessThanOrEqual(l, r) if l.hashCode() > r.hashCode() => GreaterThanOrEqual(r, l)
204201
case _ => condition // Don't reorder.
205202
}
206-
207-
private def normalizeProjectList(projectList: Seq[NamedExpression]): Seq[NamedExpression] = {
208-
projectList
209-
.map { e =>
210-
e.transformUp {
211-
case g: GetViewColumnByNameAndOrdinal => g.copy(viewDDL = None)
212-
}
213-
}
214-
.asInstanceOf[Seq[NamedExpression]]
215-
}
216203
}
217204

218205
class CteIdNormalizer {

sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/catalog/SessionCatalogSuite.scala

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -749,6 +749,13 @@ abstract class SessionCatalogSuite extends AnalysisTest with Eventually {
749749
Project(projectList, CatalystSqlParser.parsePlan(metadata.viewText.get))
750750
}
751751

752+
private def stripViewDDLFromGetViewColumbByNameAndOrdinal(plan: LogicalPlan): LogicalPlan = {
753+
plan.transformAllExpressions {
754+
case getViewColumnByNameAndOrdinal: GetViewColumnByNameAndOrdinal =>
755+
getViewColumnByNameAndOrdinal.copy(viewDDL = None)
756+
}
757+
}
758+
752759
test("look up view relation") {
753760
withBasicCatalog { catalog =>
754761
val props = CatalogTable.catalogAndNamespaceToProps("cat1", Seq("ns1"))
@@ -762,11 +769,17 @@ abstract class SessionCatalogSuite extends AnalysisTest with Eventually {
762769
// Look up a view.
763770
catalog.setCurrentDatabase("default")
764771
val view = View(desc = metadata, isTempView = false, child = getViewPlan(metadata))
765-
comparePlans(catalog.lookupRelation(TableIdentifier("view1", Some("db3"))),
772+
comparePlans(
773+
stripViewDDLFromGetViewColumbByNameAndOrdinal(
774+
catalog.lookupRelation(TableIdentifier("view1", Some("db3")))
775+
),
766776
SubqueryAlias(Seq(CatalogManager.SESSION_CATALOG_NAME, "db3", "view1"), view))
767777
// Look up a view using current database of the session catalog.
768778
catalog.setCurrentDatabase("db3")
769-
comparePlans(catalog.lookupRelation(TableIdentifier("view1")),
779+
comparePlans(
780+
stripViewDDLFromGetViewColumbByNameAndOrdinal(
781+
catalog.lookupRelation(TableIdentifier("view1"))
782+
),
770783
SubqueryAlias(Seq(CatalogManager.SESSION_CATALOG_NAME, "db3", "view1"), view))
771784
}
772785
}
@@ -781,7 +794,10 @@ abstract class SessionCatalogSuite extends AnalysisTest with Eventually {
781794
assert(metadata.viewCatalogAndNamespace == Seq(CatalogManager.SESSION_CATALOG_NAME, "db2"))
782795

783796
val view = View(desc = metadata, isTempView = false, child = getViewPlan(metadata))
784-
comparePlans(catalog.lookupRelation(TableIdentifier("view2", Some("db3"))),
797+
comparePlans(
798+
stripViewDDLFromGetViewColumbByNameAndOrdinal(
799+
catalog.lookupRelation(TableIdentifier("view2", Some("db3")))
800+
),
785801
SubqueryAlias(Seq(CatalogManager.SESSION_CATALOG_NAME, "db3", "view2"), view))
786802
}
787803
}

0 commit comments

Comments
 (0)