manuzhang commented on code in PR #19277:
URL: https://github.com/apache/iceberg/pull/19277#discussion_r4802295404


##########
spark/v4.1/spark-extensions/src/main/scala/org/apache/spark/sql/catalyst/analysis/ResolveViews.scala:
##########
@@ -84,6 +95,42 @@ case class ResolveViews(spark: SparkSession) extends 
Rule[LogicalPlan] with Look
         rewritten = true)
   }
 
+  private def hasViewColumnByOrdinal(project: Project): Boolean =
+    
project.projectList.exists(_.exists(_.isInstanceOf[GetViewColumnByOrdinal]))
+
+  private def resolveViewColumn(
+      column: GetViewColumnByOrdinal,
+      output: Seq[Attribute]): Attribute = {
+    val actualName = output.lift(column.ordinal).map(_.name)
+    if (!column.queryColumnNamesMatchSchema && actualName.isDefined &&
+      !output.exists(attr => conf.resolver(attr.name, column.expectedName))) {
+      // view schema names can differ from query output names for engines that 
don't write
+      // Spark's spark.query-column-names property, so fall back to returning 
the ordinal
+      return output(column.ordinal)

Review Comment:
   nit: avoid early return in Scala.  It looks we are only doing check in this 
function so `output(column.ordinal)` can be pulled out of this function.
   
   As for the check itself, maybe something like
   
   ```scala
   output.lift(column.ordinal).map(_.name) match {
     case Some(actualName) =>
        if (column.queryColumnNamesMatchSchema) {
           // throw error if the check fails
        }  else {
           // throw error if the check fails
        }
     case None => throw ...
   }
   ```



-- 
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