cloud-fan commented on code in PR #49027:
URL: https://github.com/apache/spark/pull/49027#discussion_r1908329899
##########
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:
I'm fine with it because it's the existing behavior, but I believe there is
a bug here. See
https://github.com/apache/spark/blob/master/sql/core/src/main/scala/org/apache/spark/sql/execution/DataSourceScanExec.scala#L389-L391
The table scan node assumes the bucket sort columns are always ascending,
but here we may sort the data in descending order, because we may remove the
`Clustering` node if the plan is already sorted by the sort columns
descendingly.
--
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]