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


##########
common/utils/src/main/resources/error/error-conditions.json:
##########
@@ -3008,6 +3013,48 @@
     ],
     "sqlState" : "42704"
   },
+  "FILE_TYPE_IN_ROUTINE_SIGNATURE_UNSUPPORTED_MAP_KEY" : {
+    "message" : [
+      "The FILE type cannot be a map key in the return type of <routineType> 
<routineName>. Use FILE only as a map value, array element, or struct field."
+    ],
+    "sqlState" : "42601"
+  },
+  "FILE_TYPE_IN_ROUTINE_SIGNATURE_UNSUPPORTED_QUALIFIER" : {
+    "message" : [
+      "The FILE type in <routineType> <routineName> does not support the 
EXTERNAL qualifier. Use FILE without a qualifier."
+    ],
+    "sqlState" : "42601"
+  },
+  "FILE_TYPE_MISSING_QUALIFIER" : {
+    "message" : [
+      "FILE type requires the EXTERNAL qualifier in a column definition. Use 
FILE EXTERNAL."

Review Comment:
   Filed as [SPARK-61301](https://issues.apache.org/jira/browse/SPARK-61301), 
which also covers the wording nit on `FILE_TYPE_UNKNOWN_WRITE`, the three 
helpers and the V1 bucket sort column error.



##########
sql/catalyst/src/main/scala/org/apache/spark/sql/errors/QueryCompilationErrors.scala:
##########
@@ -5173,6 +5184,37 @@ private[sql] object QueryCompilationErrors extends 
QueryErrorsBase with Compilat
       messageParameters = Map.empty)
   }
 
+  def fileTypeUnknownWriteError(colNames: Seq[String]): Throwable = {
+    new AnalysisException(
+      errorClass = "FILE_TYPE_UNKNOWN_WRITE",
+      messageParameters = Map(
+        "colNames" -> colNames.map(quoteIdentifier).mkString("[", ", ", "]")))
+  }
+
+  def fileTypeUnsupportedColumnUsageError(field: StructField, usage: String): 
Throwable = {
+    new AnalysisException(
+      errorClass = s"FILE_TYPE_UNSUPPORTED_COLUMN_USAGE.$usage",

Review Comment:
   Filed as part of 
[SPARK-61301](https://issues.apache.org/jira/browse/SPARK-61301).



##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/util/TypeUtils.scala:
##########
@@ -70,7 +72,8 @@ object TypeUtils extends QueryErrorsBase {
   }
 
   def checkForMapKeyType(keyType: DataType): TypeCheckResult = {
-    if (keyType.existsRecursively(dt => dt.isInstanceOf[MapType] || 
dt.isInstanceOf[VariantType])) {
+    if (keyType.existsRecursively(dt => dt.isInstanceOf[MapType] || 
dt.isInstanceOf[VariantType] ||

Review Comment:
   Filed as [SPARK-61299](https://issues.apache.org/jira/browse/SPARK-61299), 
which covers both this and @holdenk's suggestion, together with the shared 
helper @dtenedor asked for.



##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/util/TypeUtils.scala:
##########
@@ -162,4 +165,123 @@ object TypeUtils extends QueryErrorsBase {
         messageParameters = scala.collection.immutable.Map.empty)
     }
   }
+
+  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`.
+   */
+  def checkFileTypeHasQualifier(dataType: DataType): Unit = {
+    if (containsUnknownFileType(dataType)) {
+      throw QueryCompilationErrors.fileTypeMissingQualifierError()
+    }
+  }
+
+  /**
+   * Fails if any of `columns`, which a write such as CREATE TABLE AS SELECT 
stores in a table,
+   * holds a FILE without a qualifier, as a table cannot store one.
+   */
+  def checkNoUnknownFileTypeWrite(columns: Seq[Attribute]): Unit = {
+    checkNoUnknownFileTypeInColumns(columns.map(c => Seq(c.name) -> 
c.dataType))
+  }
+
+  /**
+   * Fails if a column of `schema`, which a command such as CREATE TABLE LIKE 
stores in a new
+   * table, holds a FILE without a qualifier.
+   */
+  def checkNoUnknownFileTypeInTableSchema(schema: StructType): Unit = {
+    checkNoUnknownFileTypeInColumns(schema.fields.toSeq.map(f => Seq(f.name) 
-> f.dataType))
+  }

Review Comment:
   Included in 
[SPARK-61299](https://issues.apache.org/jira/browse/SPARK-61299): the 
FILE-specific checks move from `TypeUtils` into a dedicated object as part of 
sharing the checks.



##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/CheckAnalysis.scala:
##########
@@ -1170,6 +1234,13 @@ trait CheckAnalysis extends LookupCatalog with 
QueryErrorsBase with PlanToString
               origin = operator.origin
             )
 
+          // FILE has no defined ordering, so it cannot be compared in a set 
operation.
+          case o if fileColumnInSetOperation(o).isDefined =>
+            throw QueryCompilationErrors.unsupportedSetOperationOnFileType(
+              fileCol = fileColumnInSetOperation(o).get,
+              origin = operator.origin
+            )
+

Review Comment:
   Filed as [SPARK-61302](https://issues.apache.org/jira/browse/SPARK-61302): 
whether FileType should ever define equality and hashing, and what it would 
mean. The type-level way to declare equality and ordering support is 
[SPARK-61299](https://issues.apache.org/jira/browse/SPARK-61299).



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