Skip to content

[SPARK-52417][SQL] Simplify Table properties handling in View Schema Evolution Mode #51107

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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 @@ -629,9 +629,15 @@ case class CatalogTable(
if (lastAccessTime <= 0) JString("UNKNOWN")
else JLong(lastAccessTime)

val viewQueryOutputColumns: JValue =
if (viewQueryColumnNames.nonEmpty) JArray(viewQueryColumnNames.map(JString).toList)
else JNull
val viewQueryOutputColumns: JValue = {
Copy link
Contributor Author

@szehon-ho szehon-ho Jun 7, 2025

Choose a reason for hiding this comment

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

This is for describe view query output.

Note we already seem to use the ViewSchema directly in the view resolution for SchemaEvolution mode: https://github.com/apache/spark/blob/master/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/catalog/SessionCatalog.scala#L991 iiuc

if (viewSchemaMode == SchemaEvolution) {
JArray(schema.map(_.name).map(JString).toList)
} else if (viewQueryColumnNames.nonEmpty) {
JArray(viewQueryColumnNames.map(JString).toList)
} else {
JNull
}
}

val map = mutable.LinkedHashMap[String, JValue]()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ import org.apache.spark.sql.classic.SparkSession
import org.apache.spark.sql.connector.expressions.{FieldReference, RewritableTransform}
import org.apache.spark.sql.errors.QueryCompilationErrors
import org.apache.spark.sql.execution.command.DDLUtils
import org.apache.spark.sql.execution.command.ViewHelper.generateViewProperties
import org.apache.spark.sql.execution.datasources.{CreateTable => CreateTableV1}
import org.apache.spark.sql.execution.datasources.v2.FileDataSourceV2
import org.apache.spark.sql.internal.SQLConf
Expand Down Expand Up @@ -705,16 +704,6 @@ object ViewSyncSchemaToMetaStore extends (LogicalPlan => Unit) {
}

if (redo) {
val newProperties = if (viewSchemaMode == SchemaEvolution) {
generateViewProperties(
metaData.properties,
session,
fieldNames,
fieldNames,
metaData.viewSchemaMode)
} else {
metaData.properties
}
val newSchema = if (viewSchemaMode == SchemaTypeEvolution) {
val newFields = viewQuery.schema.map {
case StructField(name, dataType, nullable, _) =>
Expand All @@ -727,9 +716,7 @@ object ViewSyncSchemaToMetaStore extends (LogicalPlan => Unit) {
}
SchemaUtils.checkColumnNameDuplication(fieldNames.toImmutableArraySeq,
session.sessionState.conf.resolver)
val updatedViewMeta = metaData.copy(
properties = newProperties,
schema = newSchema)
val updatedViewMeta = metaData.copy(schema = newSchema)
session.sessionState.catalog.alterTable(updatedViewMeta)
}
case _ => // OK
Expand Down