wecharyu commented on code in PR #49027:
URL: https://github.com/apache/spark/pull/49027#discussion_r1908221634


##########
sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/V1Writes.scala:
##########
@@ -98,16 +98,27 @@ object V1Writes extends Rule[LogicalPlan] with 
SQLConfHelper {
     assert(empty2NullPlan.output.length == query.output.length)
     val attrMap = AttributeMap(query.output.zip(empty2NullPlan.output))
 
-    // Rewrite the attribute references in the required ordering to use the 
new output.
-    val requiredOrdering = write.requiredOrdering.map(_.transform {
-      case a: Attribute => attrMap.getOrElse(a, a)
-    }.asInstanceOf[SortOrder])
+    // Rewrite the attribute references to use the new output.
+    def rewriteAttributes[T <: Expression](expr: T): T = {
+      expr.transform {
+        case a: Attribute => attrMap.getOrElse(a, a)
+      }.asInstanceOf[T]
+    }
+    val clusteringSpec = write.clusteringSpec.map { spec =>
+      ClusteringSpec(
+        clusteringKeys = spec.clusteringKeys.map(rewriteAttributes),
+        sortKeys = spec.sortKeys.map(rewriteAttributes)
+      )
+    }
+    val clusteringExpressions = 
clusteringSpec.map(_.expressions).getOrElse(Seq.empty)

Review Comment:
   The `expressions` function returns both expressions of `clusteringKeys` and 
`sortKeys`, we use it here because if the `outputOrdering` matched all 
expressions, then neither `Clustering` nor `Sort` node needs to be added here.
   
   And `isOrderingMatched` is also called in `FileFormatWriter`, so I think it 
could still accept the `Seq[Expression]` parameter : 
   
https://github.com/apache/spark/blob/0123a5ecbe6d4075b0738e9d2faac354f2cbd008/sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/FileFormatWriter.scala#L156-L160



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