Skip to content

Simpler to see expressions in explain tree mode #15163

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 18 commits into from
Mar 15, 2025
Merged

Conversation

irenjj
Copy link
Contributor

@irenjj irenjj commented Mar 11, 2025

Which issue does this PR close?

Rationale for this change

What changes are included in this PR?

Are these changes tested?

Are there any user-facing changes?

@github-actions github-actions bot added the physical-expr Changes to the physical-expr crates label Mar 11, 2025
@irenjj irenjj marked this pull request as ready for review March 12, 2025 13:15
@github-actions github-actions bot added the proto Related to proto crate label Mar 12, 2025
@alamb
Copy link
Contributor

alamb commented Mar 12, 2025

Thank you @irenjj - I will check this out tomorrow

Copy link
Contributor

@alamb alamb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you so much @irenjj -- this looks really nice ❤️

I left some documentation suggestions.

Other than that, can you please hook up this format to one of the TreeExplain implementations so we

  1. Can see what a plan would look like
  2. Make sure the API is usable

@github-actions github-actions bot added the sqllogictest SQL Logic Tests (.slt) label Mar 14, 2025
@irenjj
Copy link
Contributor Author

irenjj commented Mar 14, 2025

Thanks @alamb , have added an example for Projection, it looks better than before.

@irenjj irenjj requested a review from alamb March 14, 2025 12:21
22)┌─────────────┴─────────────┐
23)│ SortExec │
24)│ -------------------- │
25)│ v1@0 ASC NULLS LAST │
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

eventually it will be great to remove the @0 here too

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we can file a follow on PR to improve other plans 🤔

Copy link
Contributor Author

@irenjj irenjj Mar 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, I'd like to fix the expression printing format for all these plans in the next PR, since most plans' printing format are supported, filed #15238.

Copy link
Contributor

@alamb alamb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @irenjj -- I took the liberty of pushing some commits to this branch to:

  1. rename sql_formatter to fmt_sql and added documentation / example
  2. Cleaned up the printing of ProjectionExec

Let me know what you think!

24)│ files: 1 │
25)│ format: csv │
26)└───────────────────────────┘
04)│ count(Int64(1)) ROWS │
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

formatting this as 1 rather than Int64 will be great eventually too

Copy link
Contributor Author

@irenjj irenjj Mar 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a good idea! The output format of count(Int64(1)) is not controlled by fmt_sql, it's a column generated by AggregateExec, I'll try to resolve it in next pr.

Copy link
Contributor Author

@irenjj irenjj Mar 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The output of AggregateExec also seems to contain redundant information.

I debugged the code and found that the name of AggregateFunctionExpr is constructed in create_aggregate_expr_and_maybe_filter. In this function, debug information is generated for all Expr instances through Expr's SchemaDisplay.

To address this issue, I propose the following solution:

  1. Add a new member sql_name to AggregateFunctionExpr.
  2. Introduce a new method fmt_sql_name() for Expr, similar to schema_name(), and override it in AggregateFunction to generate sql_name.
  3. Modify fmt_as in AggregateExec to output aggr_expr.sql_name instead of aggr_expr.name.

I'm not sure if this idea is correct. If you have any suggestions, that would be even better.❤️

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if this idea is correct. If you have any suggestions, that would be even better.❤️

I am not sure either -- maybe we can try it and see how it looks

@@ -379,3 +396,53 @@ where

DisplayWrapper(exprs.into_iter())
}

/// Prints a [`PhysicalExpr`] in a SQL-like format
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I moved the code here and added an example

@alamb alamb changed the title Simpler to see expressions in tree explain mode Simpler to see expressions in explain tree mode Mar 14, 2025
@alamb alamb merged commit 0e77fb2 into apache:main Mar 15, 2025
28 checks passed
@alamb
Copy link
Contributor

alamb commented Mar 15, 2025

Thanks again @irenjj

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
physical-expr Changes to the physical-expr crates proto Related to proto crate sqllogictest SQL Logic Tests (.slt)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Simpler / easier to see expressions in tree explain mode
2 participants