apache / datafusion

Apache DataFusion SQL Query Engine
https://datafusion.apache.org/
Apache License 2.0
5.57k stars 1.04k forks source link

Support dot graph output in explain (analyze) #3606

Open Dandandan opened 1 year ago

Dandandan commented 1 year ago

Is your feature request related to a problem or challenge? Please describe what you are trying to do. We support converting a logical plan to a dot language graph (.dot) - I believe Ballista also supports it (by @andygrove ?) It would be great to support this as format for explain analyze

Describe the solution you'd like Return the .dot graph output when giving the FORMAT DOT as option to explain / explain analyze statements. Amazon Athena has a similar feature: https://docs.aws.amazon.com/athena/latest/ug/athena-explain-statement.html

Describe alternatives you've considered

Additional context

alamb commented 1 year ago

There is already a code to make graphviz format here: https://github.com/apache/arrow-datafusion/blob/81b57948778cfa485d8b3f2c1fe4485f3966e8e4/datafusion/expr/src/logical_plan/plan.rs#L604-L633

It might be kind of old / out of date, so might need to be updated

Perhaps we could add some new configuration option like "show_graphviz_during_explain" whihc if true would also output the graphviz output?

Dandandan commented 1 year ago

My plan is to use the presto syntax

EXPLAIN [ANALYZE] [FORMAT GRAPHVIZ|JSON|TEXT]

to control the output, which should default to TEXT (current output).

Dandandan commented 1 year ago

Added a PR for the syntax in here https://github.com/sqlparser-rs/sqlparser-rs/pull/621

andygrove commented 1 year ago

@Dandandan Since you asked, I have a PR open against Ballista related to DOT graphs - https://github.com/apache/arrow-ballista/pull/242. Feel free to review if you like. I would love to get this merged soon.

alamb commented 1 year ago

I'll try and get a sqlparser-rs release out in the next day or two

mkmik commented 1 year ago

There are many visualizers that can process the postgres explain JSON format (e.g. https://github.com/dalibo/pev2 or https://github.com/mgartner/pg_flame)

alamb commented 1 year ago

https://crates.io/crates/sqlparser/0.24.0 has been released

liurenjie1024 commented 1 year ago

Hi, @Dandandan are you still working on this?

liurenjie1024 commented 1 year ago

@alamb Seems @Dandandan not responding, I will go on with this issue, please assign it to me.

alamb commented 1 year ago

Thanks @liurenjie1024

Dandandan commented 1 year ago

Hey @liurenjie1024 , yes feel free to work on it. Thank you @liurenjie1024