This is an automated email from the ASF dual-hosted git repository.
wenchen pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/spark.git
The following commit(s) were added to refs/heads/master by this push:
new 597d49f89cab [SPARK-52447][SQL] Move GetViewColumnByNameAndOrdinal
normalization to SessionCatalogSuite
597d49f89cab is described below
commit 597d49f89cabb0e75709fdf0073f6b1a61c23ba6
Author: Vladimir Golubev <[email protected]>
AuthorDate: Thu Jun 12 15:48:38 2025 -0700
[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]>
---
.../spark/sql/catalyst/plans/NormalizePlan.scala | 17 ++---------------
.../sql/catalyst/catalog/SessionCatalogSuite.scala | 22 +++++++++++++++++++---
2 files changed, 21 insertions(+), 18 deletions(-)
diff --git
a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/plans/NormalizePlan.scala
b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/plans/NormalizePlan.scala
index b679514a2605..643dc8dc8746 100644
---
a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/plans/NormalizePlan.scala
+++
b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/plans/NormalizePlan.scala
@@ -21,7 +21,6 @@ import java.util.HashMap
import org.apache.spark.sql.catalyst.analysis.{
DeduplicateRelations,
- GetViewColumnByNameAndOrdinal,
NormalizeableRelation
}
import org.apache.spark.sql.catalyst.expressions._
@@ -160,14 +159,12 @@ object NormalizePlan extends PredicateHelper {
innerProject.child
)
aggregate.copy(child = newInnerProject)
- case Project(outerProjectList, innerProject: Project) =>
+ case project @ Project(_, innerProject: Project) =>
val newInnerProject = Project(
innerProject.projectList.sortBy(_.name),
innerProject.child
)
- Project(normalizeProjectList(outerProjectList), newInnerProject)
- case Project(projectList, child) =>
- Project(normalizeProjectList(projectList), child)
+ project.copy(child = newInnerProject)
case c: KeepAnalyzedQuery => c.storeAnalyzedQuery()
case localRelation: LocalRelation if !localRelation.data.isEmpty =>
/**
@@ -203,16 +200,6 @@ object NormalizePlan extends PredicateHelper {
case LessThanOrEqual(l, r) if l.hashCode() > r.hashCode() =>
GreaterThanOrEqual(r, l)
case _ => condition // Don't reorder.
}
-
- private def normalizeProjectList(projectList: Seq[NamedExpression]):
Seq[NamedExpression] = {
- projectList
- .map { e =>
- e.transformUp {
- case g: GetViewColumnByNameAndOrdinal => g.copy(viewDDL = None)
- }
- }
- .asInstanceOf[Seq[NamedExpression]]
- }
}
class CteIdNormalizer {
diff --git
a/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/catalog/SessionCatalogSuite.scala
b/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/catalog/SessionCatalogSuite.scala
index cfbc507fb5c7..e532ebecc442 100644
---
a/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/catalog/SessionCatalogSuite.scala
+++
b/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/catalog/SessionCatalogSuite.scala
@@ -749,6 +749,13 @@ abstract class SessionCatalogSuite extends AnalysisTest
with Eventually {
Project(projectList, CatalystSqlParser.parsePlan(metadata.viewText.get))
}
+ private def stripViewDDLFromGetViewColumbByNameAndOrdinal(plan:
LogicalPlan): LogicalPlan = {
+ plan.transformAllExpressions {
+ case getViewColumnByNameAndOrdinal: GetViewColumnByNameAndOrdinal =>
+ getViewColumnByNameAndOrdinal.copy(viewDDL = None)
+ }
+ }
+
test("look up view relation") {
withBasicCatalog { catalog =>
val props = CatalogTable.catalogAndNamespaceToProps("cat1", Seq("ns1"))
@@ -762,11 +769,17 @@ abstract class SessionCatalogSuite extends AnalysisTest
with Eventually {
// Look up a view.
catalog.setCurrentDatabase("default")
val view = View(desc = metadata, isTempView = false, child =
getViewPlan(metadata))
- comparePlans(catalog.lookupRelation(TableIdentifier("view1",
Some("db3"))),
+ comparePlans(
+ stripViewDDLFromGetViewColumbByNameAndOrdinal(
+ catalog.lookupRelation(TableIdentifier("view1", Some("db3")))
+ ),
SubqueryAlias(Seq(CatalogManager.SESSION_CATALOG_NAME, "db3",
"view1"), view))
// Look up a view using current database of the session catalog.
catalog.setCurrentDatabase("db3")
- comparePlans(catalog.lookupRelation(TableIdentifier("view1")),
+ comparePlans(
+ stripViewDDLFromGetViewColumbByNameAndOrdinal(
+ catalog.lookupRelation(TableIdentifier("view1"))
+ ),
SubqueryAlias(Seq(CatalogManager.SESSION_CATALOG_NAME, "db3",
"view1"), view))
}
}
@@ -781,7 +794,10 @@ abstract class SessionCatalogSuite extends AnalysisTest
with Eventually {
assert(metadata.viewCatalogAndNamespace ==
Seq(CatalogManager.SESSION_CATALOG_NAME, "db2"))
val view = View(desc = metadata, isTempView = false, child =
getViewPlan(metadata))
- comparePlans(catalog.lookupRelation(TableIdentifier("view2",
Some("db3"))),
+ comparePlans(
+ stripViewDDLFromGetViewColumbByNameAndOrdinal(
+ catalog.lookupRelation(TableIdentifier("view2", Some("db3")))
+ ),
SubqueryAlias(Seq(CatalogManager.SESSION_CATALOG_NAME, "db3",
"view2"), view))
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]