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/02/09 16:57:41 UTC

[GitHub] [arrow-datafusion] mustafasrepo opened a new pull request, #5228: Feature/sort enforcement refactor

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

   # 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
   
   <!--
    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.  
   -->
   As suggested by @mingmwang in the [discussion](https://github.com/apache/arrow-datafusion/pull/5171#discussion_r1099988290). Comparing ordering between schemas when there are multiple executors in between them may produce incorrect results. Although this situation may not arise in practice with the current ordering of the optimization rules. We have changed the implementation in case one encounters it (Nobody knows).
   
   # 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.
   -->
   
   With this change parallelize sort rule compares the immediate table for converting `Coalesce + Executors that do not require SingleDistribution + Sort` cascades to `Executors that do not require SingleDistribution + Sort + SortPreservingMerge` cascade.
   We also added a check that the final Sort in the cascade rule is actually a Global sort. 
   # 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)?
   -->
   We added a unit test to verify that rule only ends when Sort is a global sort. Also, the existing [test](https://github.com/synnada-ai/arrow-datafusion/blob/157e204bb35e5e1466b8d6c11846e1a15ef048e5/datafusion/core/src/physical_optimizer/sort_enforcement.rs#L1680) checks the sort comparison is done between immediate executors.
   
   # 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


[GitHub] [arrow-datafusion] mingmwang commented on pull request #5228: Feature/sort enforcement refactor

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

   The change LGTM.


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


[GitHub] [arrow-datafusion] mingmwang commented on pull request #5228: Feature/sort enforcement refactor

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

   I will review this PR carefully today.


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


[GitHub] [arrow-datafusion] ursabot commented on pull request #5228: Feature/sort enforcement refactor

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

   Benchmark runs are scheduled for baseline = 3da790214ea479626eb4114c53440dc17b737d54 and contender = 95658877dc8693a82d5046f64a5219595b64f9e3. 95658877dc8693a82d5046f64a5219595b64f9e3 is a master commit associated with this PR. Results will be available as each benchmark for each run completes.
   Conbench compare runs links:
   [Skipped :warning: Benchmarking of arrow-datafusion-commits is not supported on ec2-t3-xlarge-us-east-2] [ec2-t3-xlarge-us-east-2](https://conbench.ursa.dev/compare/runs/e074935e3a4546caad785d5db4fd866c...ef3ee7c3e43d4c03ae2466235c6bf86e/)
   [Skipped :warning: Benchmarking of arrow-datafusion-commits is not supported on test-mac-arm] [test-mac-arm](https://conbench.ursa.dev/compare/runs/735ec441b35743cfa7036367a5a4899b...d32e973f77f84a92976baeca74c88f1e/)
   [Skipped :warning: Benchmarking of arrow-datafusion-commits is not supported on ursa-i9-9960x] [ursa-i9-9960x](https://conbench.ursa.dev/compare/runs/6db42e6f7cf04940a1388e97c9aa8005...9d91656293214091a56ca01e70ab9837/)
   [Skipped :warning: Benchmarking of arrow-datafusion-commits is not supported on ursa-thinkcentre-m75q] [ursa-thinkcentre-m75q](https://conbench.ursa.dev/compare/runs/8588c39f501445c780a102458e2c9377...8fd2132a16f64570bdb14a735f3e4c1c/)
   Buildkite builds:
   Supported benchmarks:
   ec2-t3-xlarge-us-east-2: Supported benchmark langs: Python, R. Runs only benchmarks with cloud = True
   test-mac-arm: Supported benchmark langs: C++, Python, R
   ursa-i9-9960x: Supported benchmark langs: Python, R, JavaScript
   ursa-thinkcentre-m75q: Supported benchmark langs: C++, Java
   


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


[GitHub] [arrow-datafusion] alamb commented on a diff in pull request #5228: Feature/sort enforcement refactor

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


##########
datafusion/core/src/physical_optimizer/sort_enforcement.rs:
##########
@@ -1776,6 +1745,47 @@ mod tests {
         Ok(())
     }
 
+    #[tokio::test]
+    async fn test_coalesce_propagate() -> Result<()> {
+        let schema = create_test_schema()?;
+        let source = memory_exec(&schema);
+        let repartition = repartition_exec(source);
+        let coalesce_partitions = Arc::new(CoalescePartitionsExec::new(repartition));
+        let repartition = repartition_exec(coalesce_partitions);
+        let sort_exprs = vec![sort_expr("nullable_col", &schema)];
+        // Add local sort
+        let sort = Arc::new(SortExec::new_with_partitioning(
+            sort_exprs.clone(),
+            repartition,
+            true,
+            None,
+        )) as _;
+        let spm = sort_preserving_merge_exec(sort_exprs.clone(), sort);
+        let sort = sort_exec(sort_exprs, spm);
+
+        let physical_plan = sort.clone();
+        // Sort Parallelize rule should end Coalesce + Sort linkage when Sort is Global Sort
+        // Also input plan is not valid as it is. We need to add SortExec before SortPreservingMergeExec.
+        let expected_input = vec![
+            "SortExec: [nullable_col@0 ASC]",
+            "  SortPreservingMergeExec: [nullable_col@0 ASC]",
+            "    SortExec: [nullable_col@0 ASC]",
+            "      RepartitionExec: partitioning=RoundRobinBatch(10), input_partitions=1",
+            "        CoalescePartitionsExec",
+            "          RepartitionExec: partitioning=RoundRobinBatch(10), input_partitions=0",
+            "            MemoryExec: partitions=0, partition_sizes=[]",
+        ];
+        let expected_optimized = vec![
+            "SortPreservingMergeExec: [nullable_col@0 ASC]",
+            "  SortExec: [nullable_col@0 ASC]",
+            "    RepartitionExec: partitioning=RoundRobinBatch(10), input_partitions=10",
+            "      RepartitionExec: partitioning=RoundRobinBatch(10), input_partitions=0",
+            "        MemoryExec: partitions=0, partition_sizes=[]",

Review Comment:
   This plan definitely looks better than the input. 



##########
datafusion/core/src/physical_optimizer/sort_enforcement.rs:
##########
@@ -1718,8 +1687,8 @@ mod tests {
         ];
         let expected_optimized = vec![
             "SortPreservingMergeExec: [nullable_col@0 ASC]",
-            "  FilterExec: NOT non_nullable_col@1",
-            "    SortExec: [nullable_col@0 ASC]",
+            "  SortExec: [nullable_col@0 ASC]",
+            "    FilterExec: NOT non_nullable_col@1",

Review Comment:
   This plan change looks better to me as well (do filtering before 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: github-unsubscribe@arrow.apache.org

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


[GitHub] [arrow-datafusion] alamb commented on pull request #5228: Feature/sort enforcement refactor

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

   Thanks @mustafasrepo @mingmwang  and @ozankabak 🚀 


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


[GitHub] [arrow-datafusion] ozankabak commented on pull request #5228: Feature/sort enforcement refactor

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

   This is the first follow-on PR to address the minor issues that were discussed in the original PR (#5171).


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


[GitHub] [arrow-datafusion] alamb merged pull request #5228: Feature/sort enforcement refactor

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


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