dejankrak-db commented on code in PR #60535:
URL: https://github.com/apache/spark/pull/60535#discussion_r4588197364


##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/util/TypeUtils.scala:
##########
@@ -175,60 +175,69 @@ object TypeUtils extends QueryErrorsBase {
     }
   }
 
-  private def containsUnknownFileType(dataType: DataType): Boolean = {
-    dataType.existsRecursively {
-      case ft: FileType => ft.mode == FileTypeMode.UNKNOWN
-      case _ => false
-    }
-  }
-
   /**
-   * Fails if a FILE in `dataType`, at any nesting depth, has no qualifier, as 
a FILE in a table
-   * column definition must be declared `FILE EXTERNAL`.
+   * Returns the paths of the columns that hold a FILE without a qualifier, 
for a column at `path`
+   * of type `dataType`. The path descends into struct fields, so a FILE in a 
field of a struct
+   * column is reported at that field. A FILE in an array or a map is reported 
at the column of
+   * the array or map.
    */
-  def checkFileTypeHasQualifier(dataType: DataType): Unit = {
-    if (containsUnknownFileType(dataType)) {
-      throw QueryCompilationErrors.fileTypeMissingQualifierError()
-    }
+  private def unknownFileTypePaths(
+      path: Seq[String],
+      dataType: DataType): Seq[(Seq[String], DataType)] = dataType match {
+    case st: StructType =>
+      st.fields.toSeq.flatMap(f => unknownFileTypePaths(path :+ f.name, 
f.dataType))

Review Comment:
   Done in 67e95fad0c1: the walk returns no paths before descending into a 
struct when the type holds no FILE without a qualifier, and the schema 
overloads pass the schema as a struct with an empty path instead of building a 
pair per column. The reported paths and their order are unchanged.



##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/CreateTableValidation.scala:
##########
@@ -68,27 +68,33 @@ private[sql] object CreateTableValidation {
     create match {
       // The columns of CREATE TABLE AS SELECT come from its query, not from 
DDL.
       case ctas: V2CreateTableAsSelectPlan =>
-        TypeUtils.checkNoUnknownFileTypeWrite(ctas.query.output)
+        TypeUtils.checkNoUnknownFileTypeWrite(ctas.query.schema)
       case _ =>
         TypeUtils.checkFileTypeHasQualifier(create.tableSchema)
     }
-    // FILE is not comparable, so it cannot be a partition, clustering or 
write-ordering column.
-    create.partitioning.foreach { transform =>
-      val usage = transform match {
-        case _: ClusterByTransform => "CLUSTERING_COLUMN"
-        case _ => "PARTITION_COLUMN"
-      }
-      transform.references.foreach { ref =>
+    // FILE is not comparable, so it cannot be a partition, bucket, clustering 
or write-ordering
+    // column.

Review Comment:
   Done in 67e95fad0c1, the comment now names bucket sort columns.



##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/util/TypeUtils.scala:
##########
@@ -242,37 +251,37 @@ object TypeUtils extends QueryErrorsBase {
       schema: StructType,
       clusterBySpec: ClusterBySpec,
       resolver: Resolver): Unit = {
-    def find(schema: StructType, path: Seq[String]): Option[StructField] =
+    // Returns the path of the column, with the names of the schema, and its 
field.
+    def find(schema: StructType, path: Seq[String]): Option[(Seq[String], 
StructField)] =
       schema.fields.find(f => resolver(f.name, path.head)).flatMap { field =>
         (path.tail, field.dataType) match {
-          case (Seq(), _) => Some(field)
-          case (tail, s: StructType) => find(s, tail)
-          case (tail, ArrayType(s: StructType, _)) => find(s, tail)
+          case (Seq(), _) => Some(Seq(field.name) -> field)
+          case (tail, s: StructType) => find(s, tail).map { case (p, f) => 
(field.name +: p, f) }

Review Comment:
   Done in 67e95fad0c1: added `CLUSTER BY (s.f)` cases for a V1 CREATE TABLE 
and ALTER TABLE CLUSTER BY, expecting ```s`.`f```. They fail if this line is 
reverted to `find(s, tail)`.



##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/plans/logical/v2AlterTableCommands.scala:
##########
@@ -113,7 +113,7 @@ case class AddColumns(
   columnsToAdd.foreach { c =>
     TypeUtils.failWithIntervalType(c.dataType)
     TypeUtils.failUnsupportedDataType(c.dataType, conf)
-    TypeUtils.checkFileTypeHasQualifier(c.dataType)
+    TypeUtils.checkFileTypeHasQualifier(Seq(c.name -> c.dataType))

Review Comment:
   Done in 67e95fad0c1: added `ADD COLUMN s.y FILE` and `ALTER COLUMN s.x TYPE 
FILE` cases expecting the full path. The ADD COLUMN case fails if this line 
reports only the last name part.



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