jayzhan211 commented on code in PR #27470:
URL: https://github.com/apache/datafusion/pull/27470#discussion_r4614434608


##########
datafusion/physical-plan/src/render_tree.rs:
##########
@@ -195,6 +196,13 @@ fn create_tree_recursive(
         }
     }
 
+    if show_equivalences {

Review Comment:
   @marvelefe thanks for the quick update! In tree format a box shows at most 
30 lines and entries are sorted by key, so a long `facts` entry comes before 
`fetch`/`fn`/`order`/`partition` and pushes them out of the box. Here 
`PartitionedTopKExec` loses its own sort key when the option is on (my earlier 
suggestion missed this cap, sorry):
   
   ```text
   option off                     option on (this PR)
   │ emit: ... (9 lines)  │       │ emit: ... (9 lines)   │
   │ fetch: 1             │       │ facts:                │
   │ fn: row_number       │       │ order: [a@0 ASC ...   │
   │ order:               │       │   ... (16 lines)      │
   │ [c@2 DESC, d@3 ASC   │       │ fetch: 1              │
   │   NULLS LAST]        │       │ ...                   │
   │ partition: [a@0, b@1]│
   ```
   
   ```sql
   CREATE TABLE t1 (a INT, b INT, c INT, d INT) AS VALUES (1,2,3,4);
   set datafusion.explain.format = tree;
   set datafusion.explain.show_equivalences = true;
   EXPLAIN SELECT * FROM (SELECT a, b, c, d, ROW_NUMBER() OVER (PARTITION BY a, 
b ORDER BY c DESC, d) as rn FROM t1) WHERE rn <= 1;
   ```
   
   Rendering facts after the operator's entries, below a separator with their 
own line budget, keeps everything visible (and a column aliased `facts` can't 
be overwritten either). Could you also add the query above to 
`explain_tree.slt`? The current case is too short to reach the cap.
   
   ```diff
   --- a/datafusion/physical-plan/src/render_tree.rs
   +++ b/datafusion/physical-plan/src/render_tree.rs
   @@ pub struct RenderTreeNode {
        pub extra_text: HashMap<String, String>,
   +    /// Equivalence properties, rendered after `extra_text` with their own 
line
   +    /// budget so they never hide or replace the operator's entries.
   +    pub facts: Option<String>,
   @@ impl RenderTreeNode {
                extra_text,
   +            facts: None,
                child_positions: vec![],
   @@ fn create_tree_recursive(
   +    let mut node = RenderTreeNode::new(plan.name().to_string(), extra_info);
        if show_equivalences {
   -        extra_info.insert(
   -            "facts".to_string(),
   -            plan.equivalence_properties().to_string(),
   -        );
   +        node.facts = Some(plan.equivalence_properties().to_string());
        }
   -
   -    let mut node = RenderTreeNode::new(plan.name().to_string(), extra_info);
   --- a/datafusion/physical-plan/src/display.rs
   +++ b/datafusion/physical-plan/src/display.rs
   @@ fn render_box_content(
                        Self::MAX_EXTRA_LINES,
                    );
   +                if let Some(facts) = &node.facts {
   +                    let mut facts_lines = vec![];
   +                    Self::split_up_extra_info(
   +                        &HashMap::from([("facts".to_string(), 
facts.clone())]),
   +                        &mut facts_lines,
   +                        Self::MAX_EXTRA_LINES,
   +                    );
   +                    extra_info_item.extend(facts_lines);
   +                }
   ```
   
   <details><summary>The PartitionedTopKExec box with the fix applied</summary>
   
   ```text
   │    PartitionedTopKExec    │
   │    --------------------   │
   │           emit:           │
   │ [row_number() PARTITION BY│
   │   [t1.a, t1.b] ORDER BY   │
   │  [t1.c DESC NULLS FIRST,  │
   │    t1.d ASC NULLS LAST]   │
   │        RANGE BETWEEN      │
   │          UNBOUNDED        │
   │        PRECEDING AND      │
   │        CURRENT ROW]       │
   │                           │
   │          fetch: 1         │
   │       fn: row_number      │
   │                           │
   │           order:          │
   │  [c@2 DESC, d@3 ASC NULLS │
   │            LAST]          │
   │                           │
   │   partition: [a@0, b@1]   │
   │    --------------------   │
   │           facts:          │
   │   order: [a@0 ASC NULLS   │
   │       FIRST, b@1 ASC      │
   │      NULLS FIRST, c@2     │
   │    DESC NULLS FIRST, d@3  │
   │   ASC NULLS LAST] | [a@0  │
   │    ASC NULLS FIRST, b@1   │
   │      ASC NULLS FIRST,     │
   │        row_number()       │
   │     PARTITION BY [t1.a    │
   │   , t1.b] ORDER BY [t1.c  │
   │    DESC NULLS FIRST, t1   │
   │  .d ASC NULLS LAST] RANGE │
   │      BETWEEN UNBOUNDED    │
   │        PRECEDING AND      │
   │      CURRENT ROW@4 ASC    │
   │         NULLS LAST]       │
   ```
   
   The existing `explain_tree.slt` case only needs `--complete` (facts move 
below a separator). The `display` unit tests and `cargo clippy -p 
datafusion-physical-plan --all-targets -- -D warnings` pass.
   
   </details>



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