beliefer commented on code in PR #39182:
URL: https://github.com/apache/spark/pull/39182#discussion_r1056037625


##########
connector/connect/server/src/main/scala/org/apache/spark/sql/connect/planner/SparkConnectPlanner.scala:
##########
@@ -126,39 +128,37 @@ class SparkConnectPlanner(session: SparkSession) {
     SubqueryAlias(aliasIdentifier, transformRelation(alias.getInput))
   }
 
+  private def transformDeterministicOrder(rel: proto.DeterministicOrder): 
LogicalPlan = {
+    val input = Dataset.ofRows(session, transformRelation(rel.getInput))
+    // 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.logicalPlan.output
+      .filter(attr => RowOrdering.isOrderable(attr.dataType))
+      .map(SortOrder(_, Ascending))
+    if (sortOrder.nonEmpty) {
+      Sort(sortOrder, global = false, input.logicalPlan)
+    } else {
+      input.cache()
+      input.logicalPlan
+    }
+  }
+
   /**
    * All fields of [[proto.Sample]] are optional. However, given those are 
proto primitive types,
    * we cannot differentiate if the field is not or set when the field's value 
equals to the type
    * default value. In the future if this ever become a problem, one solution 
could be that to
    * wrap such fields into proto messages.
    */
   private def transformSample(rel: proto.Sample): LogicalPlan = {
-    val input = Dataset.ofRows(session, transformRelation(rel.getInput))
-    val plan = if (rel.getForceStableSort) {

Review Comment:
   We use `DeterministicOrder` message to instead `force stable sort`.



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