zhengruifeng commented on code in PR #39151:
URL: https://github.com/apache/spark/pull/39151#discussion_r1054049998
##########
connector/connect/server/src/main/scala/org/apache/spark/sql/connect/planner/SparkConnectPlanner.scala:
##########
@@ -361,6 +363,38 @@ class SparkConnectPlanner(session: SparkSession) {
}
}
+ private def transformDeterminize(rel: proto.Determinize): LogicalPlan = {
+ if (!rel.hasInput) {
+ throw InvalidPlanInput("Determinize needs a plan input")
+ }
+
+ val input = transformRelation(rel.getInput)
+ if (input.deterministic) {
+ return input
+ }
+
+ val dataset = Dataset.ofRows(session, input)
+ if (dataset.logicalPlan.deterministic || dataset.storageLevel !=
StorageLevel.NONE) {
+ return dataset.logicalPlan
+ }
+
+ // It is possible that the underlying dataframe doesn't guarantee the
ordering of rows in its
+ // constituent partitions each time a split is materialized which could
result in
+ // overlapping splits. To prevent this, we explicitly sort each input
partition to make the
+ // ordering deterministic. Note that MapTypes cannot be sorted and are
explicitly pruned out
+ // from the sort order.
+ val sortOrder = input.output
+ .filter(attr => RowOrdering.isOrderable(attr.dataType))
+ .map(SortOrder(_, Ascending))
+ if (sortOrder.nonEmpty) {
+ Sort(sortOrder, global = false, input)
Review Comment:
I suspect whether the sort here make dataset deterministic, maybe we should
apply this sorter
https://github.com/apache/spark/blob/master/sql/core/src/main/scala/org/apache/spark/sql/execution/exchange/ShuffleExchangeExec.scala#L338-L369
--
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]