pan3793 commented on code in PR #36995:
URL: https://github.com/apache/spark/pull/36995#discussion_r922005824


##########
sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/v2/DistributionAndOrderingUtils.scala:
##########
@@ -53,16 +63,27 @@ object DistributionAndOrderingUtils {
         query
       }
 
-      val ordering = toCatalystOrdering(write.requiredOrdering, query)
+      val ordering = toCatalystOrdering(write.requiredOrdering, query, 
funCatalogOpt)
       val queryWithDistributionAndOrdering = if (ordering.nonEmpty) {
-        Sort(ordering, global = false, queryWithDistribution)
+        Sort(
+          ordering.map(ur => 
resolveTransformExpression(ur).asInstanceOf[SortOrder]),
+          global = false,
+          queryWithDistribution)
       } else {
         queryWithDistribution
       }
 
-      queryWithDistributionAndOrdering
+      // Apply typeCoercionRules
+      SimpleAnalyzer.execute(queryWithDistributionAndOrdering)
 
     case _ =>
       query
   }
+
+  def resolveTransformExpression(expr: Expression): Expression = 
expr.transform {
+    case TransformExpression(scalarFunc: ScalarFunction[_], arguments, 
Some(numBuckets)) =>

Review Comment:
   SPARK-37377(#35657) changes the common code used by V2 reading & writing, 
converting the `Transform` to the `TransformExpression`. 
   If wanted, we can skip `TransformExpression` and resolve `Transform` to 
`ApplyFunctionExpression` / `Invoke` / `StaticInvoke` directly in V2 writing, 
but this may cause V2 reading & writing to share less code.



-- 
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: reviews-unsubscr...@spark.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org

Reply via email to