You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@datafusion.apache.org by "Standing-Man (via GitHub)" <gi...@apache.org> on 2025/03/11 03:13:19 UTC

[PR] Implement tree rendering for `SortPreservingMergeExec` [datafusion]

Standing-Man opened a new pull request, #15140:
URL: https://github.com/apache/datafusion/pull/15140

   ## 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 #15139 and Part of #14914.
   
   ## 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.  
   -->
   
   ## 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.
   -->
   Implement tree rendering for `SortPreservingMergeExec`
   
   ## 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)?
   -->
   Yes
   
   ## 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@datafusion.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [PR] Implement tree rendering for `SortPreservingMergeExec` [datafusion]

Posted by "irenjj (via GitHub)" <gi...@apache.org>.
irenjj commented on code in PR #15140:
URL: https://github.com/apache/datafusion/pull/15140#discussion_r1989258369


##########
datafusion/physical-plan/src/sorts/sort_preserving_merge.rs:
##########
@@ -186,8 +186,15 @@ impl DisplayAs for SortPreservingMergeExec {
                 Ok(())
             }
             DisplayFormatType::TreeRender => {
-                // TODO: collect info
-                write!(f, "")
+                for (i, e) in self.expr().iter().enumerate() {
+                    let e = e.to_string();
+                    writeln!(f, "expr{i}={e}")?;
+                }

Review Comment:
   In the latest version(#15125), we are no longer limited to using KV to represent each line of output, maybe we can print sorted keys without the prefix `expr:` like:
   ```
   date@0 ASC NULLS LAST,time@2 ASC NULLS LAST,...
   ```



-- 
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@datafusion.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [PR] Implement tree rendering for `SortPreservingMergeExec` [datafusion]

Posted by "irenjj (via GitHub)" <gi...@apache.org>.
irenjj commented on code in PR #15140:
URL: https://github.com/apache/datafusion/pull/15140#discussion_r1989258369


##########
datafusion/physical-plan/src/sorts/sort_preserving_merge.rs:
##########
@@ -186,8 +186,15 @@ impl DisplayAs for SortPreservingMergeExec {
                 Ok(())
             }
             DisplayFormatType::TreeRender => {
-                // TODO: collect info
-                write!(f, "")
+                for (i, e) in self.expr().iter().enumerate() {
+                    let e = e.to_string();
+                    writeln!(f, "expr{i}={e}")?;
+                }

Review Comment:
   In the latest version(#15125), we are no longer limited to using KV to represent each line of output, so as @2010YOUY01 said, may be we can print sorted keys without the prefix `expr:` like:
   ```
   sort keys:
   
   date@0 ASC NULLS LAST
   
   time@2 ASC NULLS LAST
   
   ...
   ```



-- 
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@datafusion.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [PR] Implement tree rendering for `SortPreservingMergeExec` [datafusion]

Posted by "irenjj (via GitHub)" <gi...@apache.org>.
irenjj commented on code in PR #15140:
URL: https://github.com/apache/datafusion/pull/15140#discussion_r1989258369


##########
datafusion/physical-plan/src/sorts/sort_preserving_merge.rs:
##########
@@ -186,8 +186,15 @@ impl DisplayAs for SortPreservingMergeExec {
                 Ok(())
             }
             DisplayFormatType::TreeRender => {
-                // TODO: collect info
-                write!(f, "")
+                for (i, e) in self.expr().iter().enumerate() {
+                    let e = e.to_string();
+                    writeln!(f, "expr{i}={e}")?;
+                }

Review Comment:
   In the latest version(#15125), we are no longer limited to using KV to represent each line of output, so as @2010YOUY01 said, may be we can print sorted keys without the prefix `expr:` like:
   ```
   date@0 ASC NULLS LAST
   
   time@2 ASC NULLS LAST
   
   ...
   ```



-- 
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@datafusion.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [PR] Implement tree rendering for `SortPreservingMergeExec` [datafusion]

Posted by "2010YOUY01 (via GitHub)" <gi...@apache.org>.
2010YOUY01 commented on PR #15140:
URL: https://github.com/apache/datafusion/pull/15140#issuecomment-2712575632

   Thank you for making this happen. 
   
   I have a suggestion: I think the only field needed inside `SPM` is the sort keys, how about making it consistent with those in `SortExec`? https://github.com/apache/datafusion/pull/15077/files#diff-1e143b33b083f63548925777992d4b79de3eb3fccbdcf37d35eff841717533d2 
   1. Use `sort keys` instead of `expr` to be more explicit
   2. If there are multiple sort key, print them together like `sort keys: col1 asc nulls first, col2 desc nulls last`
   


-- 
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@datafusion.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [PR] Implement tree rendering for `SortPreservingMergeExec` [datafusion]

Posted by "irenjj (via GitHub)" <gi...@apache.org>.
irenjj commented on code in PR #15140:
URL: https://github.com/apache/datafusion/pull/15140#discussion_r1989268937


##########
datafusion/physical-plan/src/sorts/sort_preserving_merge.rs:
##########
@@ -186,8 +186,15 @@ impl DisplayAs for SortPreservingMergeExec {
                 Ok(())
             }
             DisplayFormatType::TreeRender => {
-                // TODO: collect info
-                write!(f, "")
+                for (i, e) in self.expr().iter().enumerate() {
+                    let e = e.to_string();
+                    writeln!(f, "expr{i}={e}")?;
+                }
+                if let Some(fetch) = self.fetch {
+                    writeln!(f, "fetch={fetch}")?;

Review Comment:
   Nitpick: To be compatible with other `Sort*` physical plan, we'd better use `limit`



##########
datafusion/physical-plan/src/sorts/sort_preserving_merge.rs:
##########
@@ -186,8 +186,15 @@ impl DisplayAs for SortPreservingMergeExec {
                 Ok(())
             }
             DisplayFormatType::TreeRender => {
-                // TODO: collect info
-                write!(f, "")
+                for (i, e) in self.expr().iter().enumerate() {
+                    let e = e.to_string();
+                    writeln!(f, "expr{i}={e}")?;
+                }

Review Comment:
   In the latest version(#15125), we are no longer limited to using KV to represent each line of output, so as @2010YOUY01 said, may be we can print sorted keys with out the prefix `expr:` like:
   ```
   date@0 ASC NULLS LAST
   
   time@2 ASC NULLS LAST
   
   ...
   ```



-- 
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@datafusion.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [PR] Implement tree rendering for `SortPreservingMergeExec` [datafusion]

Posted by "irenjj (via GitHub)" <gi...@apache.org>.
irenjj commented on code in PR #15140:
URL: https://github.com/apache/datafusion/pull/15140#discussion_r1989258369


##########
datafusion/physical-plan/src/sorts/sort_preserving_merge.rs:
##########
@@ -186,8 +186,15 @@ impl DisplayAs for SortPreservingMergeExec {
                 Ok(())
             }
             DisplayFormatType::TreeRender => {
-                // TODO: collect info
-                write!(f, "")
+                for (i, e) in self.expr().iter().enumerate() {
+                    let e = e.to_string();
+                    writeln!(f, "expr{i}={e}")?;
+                }

Review Comment:
   In the latest version(#15125), we are no longer limited to using KV to represent each line of output, maybe we can print sorted keys without the prefix `expr:` like:
   ```
   sort keys:
   
   date@0 ASC NULLS LAST
   
   time@2 ASC NULLS LAST
   
   ...
   ```



-- 
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@datafusion.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [PR] Implement tree rendering for `SortPreservingMergeExec` [datafusion]

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

   Thank you @Standing-Man and @2010YOUY01 


-- 
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@datafusion.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [PR] Implement tree rendering for `SortPreservingMergeExec` [datafusion]

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


-- 
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@datafusion.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [PR] Implement tree rendering for `SortPreservingMergeExec` [datafusion]

Posted by "Standing-Man (via GitHub)" <gi...@apache.org>.
Standing-Man commented on PR #15140:
URL: https://github.com/apache/datafusion/pull/15140#issuecomment-2716161874

   Hi @2010YOUY01, @alamb, @irenjj and @Weijun-H, Thank you for your suggestions. I have implemented them in the new commit.


-- 
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@datafusion.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [PR] Implement tree rendering for `SortPreservingMergeExec` [datafusion]

Posted by "irenjj (via GitHub)" <gi...@apache.org>.
irenjj commented on code in PR #15140:
URL: https://github.com/apache/datafusion/pull/15140#discussion_r1990647427


##########
datafusion/sqllogictest/test_files/explain_tree.slt:
##########
@@ -1353,31 +1353,34 @@ ORDER BY "date", "time";
 physical_plan
 01)┌───────────────────────────┐
 02)│  SortPreservingMergeExec  │
-03)└─────────────┬─────────────┘
-04)┌─────────────┴─────────────┐
-05)│    CoalesceBatchesExec    │
+03)│    --------------------   │
+04)│   date@0 ASC NULLS LAST,  │
+05)│    time@2 ASC NULLS LAST  │

Review Comment:
   LGTM. This looks much better than the previous version. I think other Sort* physical plans can do the same.👍
   Thanks @Standing-Man 



-- 
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@datafusion.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org