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


##########
sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/rules.scala:
##########
@@ -293,6 +295,8 @@ case class PreprocessTableCreation(catalog: SessionCatalog) 
extends Rule[Logical
 
         c.copy(tableDesc = normalizedTable, query = Some(reorderedQuery))
       } else {
+        checkFileTypeHasQualifier(tableDesc.schema)

Review Comment:
   Filed as [SPARK-61297](https://issues.apache.org/jira/browse/SPARK-61297), 
together with the `ACCEPT_ANY_SCHEMA` write path. Its description and this PR's 
description say it must be fixed before `spark.sql.fileType.enabled` is enabled 
by default.



##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/ResolveSchemaEvolution.scala:
##########
@@ -49,6 +49,14 @@ object ResolveSchemaEvolution extends Rule[LogicalPlan] {
     case write: WriteWithSchemaEvolution if 
write.pendingSchemaChanges.nonEmpty =>
       write.table match {
         case relation @ ExtractV2CatalogAndIdentifier(catalog, ident) =>
+          // A table cannot store a FILE without a qualifier, so schema 
evolution cannot add one.
+          // This is checked before the catalog changes the table.
+          
TypeUtils.checkNoUnknownFileTypeInColumns(write.pendingSchemaChanges.collect {

Review Comment:
   Filed as [SPARK-61297](https://issues.apache.org/jira/browse/SPARK-61297), 
together with the Declarative Pipelines path, as a blocker for enabling 
`spark.sql.fileType.enabled` by default.



##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/CheckAnalysis.scala:
##########
@@ -1236,6 +1295,25 @@ trait CheckAnalysis extends LookupCatalog with 
QueryErrorsBase with PlanToString
     }
   }
 
+  /**
+   * Checks that user-defined routines that are not created by SQL DDL, such 
as Python UDFs and
+   * registered Scala UDFs, declare only a plain FILE in their return type, as
+   * [[TypeUtils.checkNoQualifierInRegisteredRoutineReturnType]] does when 
they are registered.
+   * A non-scalar Python UDF is skipped, as its data type is the schema of the 
rows it returns.
+   */
+  private def checkFileTypeInUserDefinedRoutines(plan: LogicalPlan): Unit = {
+    if (SQLConf.get.isFileTypeEnabled) {
+      plan.foreach { operator =>
+        operator.expressions.foreach(_.foreach {
+          case udf: PythonUDF if !PythonUDF.isScalarPythonUDF(udf) =>

Review Comment:
   Filed as [SPARK-61298](https://issues.apache.org/jira/browse/SPARK-61298), 
to settle with the PySpark support of the FILE type.



##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/CheckAnalysis.scala:
##########
@@ -160,13 +165,31 @@ trait CheckAnalysis extends LookupCatalog with 
QueryErrorsBase with PlanToString
     case _ => None
   }
 
+  protected def fileColumnInSetOperation(plan: LogicalPlan): Option[Attribute] 
= plan match {
+    case _: Intersect | _: Except | _: Distinct =>
+      plan.output.find(a => hasFileType(a.dataType))
+    case d: Deduplicate =>
+      d.keys.find(a => hasFileType(a.dataType))
+    case d: DeduplicateWithinWatermark =>
+      d.keys.find(a => hasFileType(a.dataType))
+    case _ => None
+  }
+
   protected def variantExprInPartitionExpression(plan: LogicalPlan): 
Option[Expression] =
     plan match {
       case r: RepartitionByExpression =>
         r.partitionExpressions.find(e => hasVariantType(e.dataType))
       case _ => None
     }
 
+  // Covers both REPARTITION / DISTRIBUTE BY and the REBALANCE hint.
+  protected def fileExprInPartitionExpression(plan: LogicalPlan): 
Option[Expression] =
+    plan match {
+      case r: HasPartitionExpressions =>

Review Comment:
   Filed as [SPARK-61299](https://issues.apache.org/jira/browse/SPARK-61299): a 
type-level way to declare equality and ordering support, shared checks for MAP, 
VARIANT and FILE, and extending the VARIANT checks to `REBALANCE` and 
`DeduplicateWithinWatermark`.



##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/resolver/OperatorWithUncomparableTypeValidator.scala:
##########
@@ -46,6 +47,10 @@ object OperatorWithUncomparableTypeValidator {
           if (hasVariantType(element.dataType)) {
             throwUnsupportedSetOperationOnVariantType(element, 
unsupportedOperator)
           }
+
+          if (hasFileType(element.dataType)) {

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



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