You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by "mustafasrepo (via GitHub)" <gi...@apache.org> on 2023/11/14 11:50:38 UTC

[PR] Preserve all of the valid orderings during merging. [arrow-datafusion]

mustafasrepo opened a new pull request, #8169:
URL: https://github.com/apache/arrow-datafusion/pull/8169

   ## Which issue does this PR close?
   
   <!--
   We generally require a GitHub issue to be filed for all bug fixes and enhancements and this helps us generate change logs for our releases. You can link an issue to this PR using the GitHub syntax. For example `Closes #123` indicates that this PR will close issue #123.
   -->
   
   Closes #.
   
   ## Rationale for this change
   Currently during merging (`SortPreservingMergeExec`) we can only preserve single ordering of the one of the valid orderings of the table.
   
   <!--
    Why are you proposing this change? If this is already explained clearly in the issue then this section is not needed.
    Explaining clearly why changes are proposed helps reviewers understand your changes and offer better suggestions for fixes.  
   -->
   
   ## What changes are included in this PR?
   
   <!--
   There is no need to duplicate the description in the issue here but it is sometimes worth providing a summary of the individual changes in this PR.
   -->
   
   ## Are these changes tested?
   
   <!--
   We typically require tests for all PRs in order to:
   1. Prevent the code from being accidentally broken by subsequent changes
   2. Serve as another way to document the expected behavior of the code
   
   If tests are not included in your PR, please explain why (for example, are they covered by existing tests)?
   -->
   
   ## Are there any user-facing changes?
   
   <!--
   If there are user-facing changes then we may require documentation to be updated before approving the PR.
   -->
   
   <!--
   If there are any breaking changes to public APIs, please add the `api change` label.
   -->
   


-- 
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: github-unsubscribe@arrow.apache.org

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


Re: [PR] Preserve all of the valid orderings during merging. [arrow-datafusion]

Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on PR #8169:
URL: https://github.com/apache/arrow-datafusion/pull/8169#issuecomment-1811540241

   Thank you @mustafasrepo  -- this is very neat


-- 
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: github-unsubscribe@arrow.apache.org

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


Re: [PR] Preserve all of the valid orderings during merging. [arrow-datafusion]

Posted by "tustvold (via GitHub)" <gi...@apache.org>.
tustvold commented on PR #8169:
URL: https://github.com/apache/arrow-datafusion/pull/8169#issuecomment-1812155562

   This PR appears to have broken logic merge conflicts that have broken CI - https://github.com/apache/arrow-datafusion/pull/8186
   
   @ozankabak could you take a look? 


-- 
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: github-unsubscribe@arrow.apache.org

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


Re: [PR] Preserve all of the valid orderings during merging. [arrow-datafusion]

Posted by "ozankabak (via GitHub)" <gi...@apache.org>.
ozankabak commented on code in PR #8169:
URL: https://github.com/apache/arrow-datafusion/pull/8169#discussion_r1392506421


##########
datafusion/physical-expr/src/equivalence.rs:
##########
@@ -575,10 +588,19 @@ impl OrderingEquivalenceClass {
         }
     }
 
-    /// Gets the first ordering entry in this ordering equivalence class.
-    /// This is one of the many valid orderings (if there are multiple).
+    /// Gets the concatenated version of the all orderings.
+    /// if orderings are [a ASC, b ASC] and [c ASC, d ASC]
+    /// Returns [a ASC, b ASC, c ASC, d ASC].
+    /// This ensures that during during merging
+    /// [a ASC, b ASC] and [c ASC, d ASC] are still valid.
     pub fn output_ordering(&self) -> Option<LexOrdering> {
-        self.orderings.first().cloned()
+        let output_ordering = self
+            .orderings
+            .iter()
+            .flat_map(|ordering| ordering.to_vec())
+            .collect::<Vec<_>>();

Review Comment:
   Nit: We can probably write this more idiomatically and avoid collecting individual pieces.



##########
datafusion/physical-expr/src/equivalence.rs:
##########
@@ -575,10 +588,19 @@ impl OrderingEquivalenceClass {
         }
     }
 
-    /// Gets the first ordering entry in this ordering equivalence class.
-    /// This is one of the many valid orderings (if there are multiple).
+    /// Gets the concatenated version of the all orderings.
+    /// if orderings are [a ASC, b ASC] and [c ASC, d ASC]
+    /// Returns [a ASC, b ASC, c ASC, d ASC].
+    /// This ensures that during during merging
+    /// [a ASC, b ASC] and [c ASC, d ASC] are still valid.

Review Comment:
   ```suggestion
       /// Returns the concatenation of all the orderings. This enables merge
       /// operations to preserve all equivalent orderings simultaneously.
   ```



##########
datafusion/physical-plan/src/repartition/mod.rs:
##########
@@ -472,9 +472,6 @@ impl ExecutionPlan for RepartitionExec {
         if !self.maintains_input_order()[0] {
             result.clear_orderings();
         }
-        if self.preserve_order {
-            result = result.with_reorder(self.sort_exprs().unwrap_or_default().to_vec())
-        }

Review Comment:
   For other reviewers: This is the key change that avoids losing alternative orderings.



-- 
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: github-unsubscribe@arrow.apache.org

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


Re: [PR] Preserve all of the valid orderings during merging. [arrow-datafusion]

Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on code in PR #8169:
URL: https://github.com/apache/arrow-datafusion/pull/8169#discussion_r1393420890


##########
datafusion/physical-expr/src/equivalence.rs:
##########
@@ -575,10 +588,13 @@ impl OrderingEquivalenceClass {
         }
     }
 
-    /// Gets the first ordering entry in this ordering equivalence class.
-    /// This is one of the many valid orderings (if there are multiple).
+    /// Returns the concatenation of all the orderings. This enables merge
+    /// operations to preserve all equivalent orderings simultaneously.
     pub fn output_ordering(&self) -> Option<LexOrdering> {
-        self.orderings.first().cloned()
+        let output_ordering =
+            self.orderings.iter().flatten().cloned().collect::<Vec<_>>();
+        let output_ordering = collapse_lex_ordering(output_ordering);

Review Comment:
   this is another core change, right? It preserves all the possible orderings



-- 
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: github-unsubscribe@arrow.apache.org

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


Re: [PR] Preserve all of the valid orderings during merging. [arrow-datafusion]

Posted by "mustafasrepo (via GitHub)" <gi...@apache.org>.
mustafasrepo commented on code in PR #8169:
URL: https://github.com/apache/arrow-datafusion/pull/8169#discussion_r1393660010


##########
datafusion/physical-expr/src/equivalence.rs:
##########
@@ -575,10 +588,13 @@ impl OrderingEquivalenceClass {
         }
     }
 
-    /// Gets the first ordering entry in this ordering equivalence class.
-    /// This is one of the many valid orderings (if there are multiple).
+    /// Returns the concatenation of all the orderings. This enables merge
+    /// operations to preserve all equivalent orderings simultaneously.
     pub fn output_ordering(&self) -> Option<LexOrdering> {
-        self.orderings.first().cloned()
+        let output_ordering =
+            self.orderings.iter().flatten().cloned().collect::<Vec<_>>();
+        let output_ordering = collapse_lex_ordering(output_ordering);

Review Comment:
   Yes, this is the place where we concatenate all valid orderings so that they can be preserved during merge



-- 
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: github-unsubscribe@arrow.apache.org

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


Re: [PR] Preserve all of the valid orderings during merging. [arrow-datafusion]

Posted by "ozankabak (via GitHub)" <gi...@apache.org>.
ozankabak merged PR #8169:
URL: https://github.com/apache/arrow-datafusion/pull/8169


-- 
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: github-unsubscribe@arrow.apache.org

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


Re: [PR] Preserve all of the valid orderings during merging. [arrow-datafusion]

Posted by "ozankabak (via GitHub)" <gi...@apache.org>.
ozankabak commented on PR #8169:
URL: https://github.com/apache/arrow-datafusion/pull/8169#issuecomment-1811976465

   Thanks @alamb, I will go ahead and merge this then. If you encounter any issue related to this, please let us know so we can promptly fix it


-- 
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: github-unsubscribe@arrow.apache.org

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