Skip to content
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

feat: Add display_pg_json for LogicalPlan #9789

Merged
merged 4 commits into from
Mar 29, 2024

Conversation

liurenjie1024
Copy link
Contributor

Which issue does this PR close?

Related #3606

Rationale for this change

This comment reminds me to have a try on pg json plan, and the visualizer look great to me since we don't need to consider style, but just nodes.

What changes are included in this PR?

Add a method to convert logical plan to postgresql json plan format, and tested in dalibo.

image

Are these changes tested?

Tested in unittest.

Are there any user-facing changes?

No.

@github-actions github-actions bot added the logical-expr Logical plan and expressions label Mar 25, 2024
@liurenjie1024
Copy link
Contributor Author

cc @andygrove Could you help to review this? It helps us to do further debugging for query optimizer.

@alamb
Copy link
Contributor

alamb commented Mar 27, 2024

This looks pretty awesome -- thank you @liurenjie1024

I am behind on reviews this week but if no one beats me to it I will review this PR in the next day or two

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.

Thanks @liurenjie1024 - I think this is a really neat feature.

I had a few suggestions on how to improve the code, but I think it could also be merged as is and we can clean it up as a follow on.

Let me know what you want to do.

Thanks again!

datafusion/expr/Cargo.toml Show resolved Hide resolved
@@ -221,6 +229,488 @@ impl<'a, 'b> TreeNodeVisitor for GraphvizVisitor<'a, 'b> {
}
}

/// Formats plans to display as postgresql plan json 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 suggest we add a link here to the spec of the postgresql plan format

Copy link
Contributor Author

@liurenjie1024 liurenjie1024 Mar 29, 2024

Choose a reason for hiding this comment

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

I've mentioned that there is no formal spec for this format. But it seems that the format is relative simple, it mainly requires Node Type as name, Output as schema, and Plans property as children. Others are not required and visualizer can display them in misc. I have an example in comments for it.

datafusion/expr/src/logical_plan/display.rs Outdated Show resolved Hide resolved
@@ -1302,6 +1303,26 @@ impl LogicalPlan {
Wrapper(self)
}

/// Return a `format`able structure that produces plan in postgresql JSON format.
Copy link
Contributor

Choose a reason for hiding this comment

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

Likewise here it would be nice to add a link to the spec

Copy link
Contributor Author

Choose a reason for hiding this comment

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

See comments above.

datafusion/expr/src/logical_plan/plan.rs Outdated Show resolved Hide resolved
datafusion/expr/src/logical_plan/plan.rs Outdated Show resolved Hide resolved
@alamb
Copy link
Contributor

alamb commented Mar 29, 2024

Thanks @liurenjie1024 -- I'll plan to merge this tomorrow unless anyone else would like to comment

Copy link
Member

@andygrove andygrove left a comment

Choose a reason for hiding this comment

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

This is very cool. Thanks @liurenjie1024

@alamb alamb merged commit 2d02329 into apache:main Mar 29, 2024
24 checks passed
Lordworms pushed a commit to Lordworms/arrow-datafusion that referenced this pull request Apr 1, 2024
* feat: Add display_pg_json for LogicalPlan

* Fix lints

* Fix comments

* Fix format
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
logical-expr Logical plan and expressions
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants