bmorck commented on code in PR #17499:
URL: https://github.com/apache/iceberg/pull/17499#discussion_r3755162320


##########
spark/v4.1/spark-extensions/src/main/scala/org/apache/spark/sql/catalyst/analysis/ResolveViews.scala:
##########
@@ -111,16 +119,72 @@ case class ResolveViews(spark: SparkSession) extends 
Rule[LogicalPlan] with Look
 
     // Apply the field aliases and column comments
     // This logic differs from how Spark handles views in 
SessionCatalog.fromCatalogTable.
-    // This is more strict because it doesn't allow resolution by field name.
+    // BINDING is more strict because it doesn't allow resolution by field 
name. COMPENSATION and
+    // TYPE_EVOLUTION coerce as SessionCatalog.castColToType does for those 
modes. Every mode keeps
+    // the stored name and metadata; only the coercion differs.
+    val mode = viewSchemaMode
     val aliases = view.schema.fields.zipWithIndex.map { case (expected, pos) =>
       val attr = GetColumnByOrdinal(pos, expected.dataType)
-      Alias(UpCast(attr, expected.dataType), expected.name)(explicitMetadata =
-        Some(expected.metadata))
+      val coerced =
+        if (mode == SparkSQLProperties.VIEW_SCHEMA_MODE_COMPENSATION) {
+          Cast(attr, expected.dataType, ansiEnabled = true)
+        } else if (mode == SparkSQLProperties.VIEW_SCHEMA_MODE_TYPE_EVOLUTION) 
{
+          attr

Review Comment:
   I did a deep dive with claude and it doesn't look like field IDs are 
consulted on this path as is. So this shouldn't change that. If a column is 
dropped and re-added under the same name, the view's SQL resolves against the 
table by name so it would bind to the new column before and after this change. 
   
   Looks like the relevant path is:
   
   > 
spark/v4.1/spark/src/main/java/org/apache/iceberg/spark/source/SparkView.java#L80-L86
   
spark/v4.1/spark/src/main/java/org/apache/iceberg/spark/SparkSchemaUtil.java#L96-L98
   
spark/v4.1/spark/src/main/java/org/apache/iceberg/spark/TypeToSparkType.java#L76-L77
   
spark/v4.1/spark/src/main/java/org/apache/iceberg/spark/TypeToSparkType.java#L197-L202
   > 
   > SparkView.schema() (80) calls SparkSchemaUtil.convert (96), which visits 
with TypeToSparkType, where each field's metadata comes from 
fieldMetadata(field.fieldId()) (76) — and that returns Metadata.empty() for 
anything that isn't a metadata column



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to