datafusion-ballista icon indicating copy to clipboard operation
datafusion-ballista copied to clipboard

feat: make it user configurable to display plans as tree renderer

Open milenkovicm opened this issue 7 months ago • 17 comments

Is your feature request related to a problem or challenge? Please describe what you are trying to do.

job REST endpoint returns plans as single line per node:

curl -sv http://localhost:50050/api/job/8Am4heu |jq

{
  "job_id": "8Am4heu",
  "job_name": "",
  "job_status": "Completed. Produced 1 partition containing 1 row. Elapsed time: 13125 ms.",
  "status": "Completed",
  "num_stages": 1,
  "completed_stages": 1,
  "percent_complete": 100,
  "start_time": 1777541048696,
  "end_time": 1777541061821,
  "logical_plan": "Projection: Int64(1)\n  EmptyRelation: rows=1",
  "physical_plan": "ProjectionExec: expr=[1 as Int64(1)]\n  PlaceholderRowExec\n",
  "stage_plan": "ExecutionGraph[job_id=8Am4heu, session_id=32ab0721-562a-47fa-a420-7dcc24e59f91, available_tasks=0, is_successful=true]\n=========SuccessfulStage[stage_id=1.0, partitions=1]=========\nShuffleWriterExec: partitioning: None, metrics=[output_rows=1, input_rows=1, repart_time=1ns, write_time=1.67ms]\n  ProjectionExec: expr=[1 as Int64(1)], metrics=[output_rows=1, elapsed_compute=296.83µs, output_bytes=8.0 B, output_batches=1, expr_0_eval_time=168.71µs]\n    PlaceholderRowExec, metrics=[]\n"
}

Describe the solution you'd like

make it user configurable to return plans as tree renderer

displayable(running_stage.plan.as_ref()).indent(false).to_string()) -> displayable(running_stage.plan.as_ref()).tree_render() .to_string())

Describe alternatives you've considered

Additional context

milenkovicm avatar Apr 30 '26 15:04 milenkovicm

cc @sandugood if you're interested

milenkovicm avatar Apr 30 '26 15:04 milenkovicm

take

sandugood avatar Apr 30 '26 19:04 sandugood

Cc @martin-g i guess it should not make problems on TUI

milenkovicm avatar Apr 30 '26 20:04 milenkovicm

make it user configurable to return plans as tree renderer

with a query parameter ?!

martin-g avatar Apr 30 '26 20:04 martin-g

make it user configurable to return plans as tree renderer

with a query parameter ?!

I think query parameter seems good for this something like: api/job/8Am4heu?plan_format=tree

sandugood avatar Apr 30 '26 20:04 sandugood

I have no preference, query parameter looks like good option. You have other preference?

milenkovicm avatar Apr 30 '26 20:04 milenkovicm

Cc @danielhumanmod now we have explain and analyse maybe we could support tree renderer there as well?

milenkovicm avatar Apr 30 '26 20:04 milenkovicm

Cc @danielhumanmod now we have explain and analyse maybe we could support tree renderer there as well?

Yeah, that sounds like a good improvement.

One thing I am thinking is how users should request the tree format for EXPLAIN / EXPLAIN ANALYZE.

One option is to extend the SQL syntax, for example:

EXPLAIN (FORMAT TREE) SELECT ...
EXPLAIN ANALYZE (FORMAT TREE) SELECT ...

Another option is to use a session config:

let config = SessionConfig::new_with_ballista()
    .set_str("ballista.explain.plan_format", "tree")...

or from SQL:

SET ballista.explain.plan_format = 'tree';

The first option seems nicer from a user-facing SQL perspective, while the second one may be smaller to introduce on the Ballista side. I’d be curious what the community prefers here.

danielhumanmod avatar May 01 '26 01:05 danielhumanmod

@danielhumanmod current datafusion behaviour

> explain format indent select 1;
+---------------+--------------------------------------+
| plan_type     | plan                                 |
+---------------+--------------------------------------+
| logical_plan  | Projection: Int64(1)                 |
|               |   EmptyRelation: rows=1              |
| physical_plan | ProjectionExec: expr=[1 as Int64(1)] |
|               |   PlaceholderRowExec                 |
|               |                                      |
+---------------+--------------------------------------+
2 row(s) fetched.
Elapsed 0.003 seconds.

> explain select 1;
+---------------+-------------------------------+
| plan_type     | plan                          |
+---------------+-------------------------------+
| physical_plan | ┌───────────────────────────┐ |
|               | │       ProjectionExec      │ |
|               | │    --------------------   │ |
|               | │        Int64(1): 1        │ |
|               | └─────────────┬─────────────┘ |
|               | ┌─────────────┴─────────────┐ |
|               | │     PlaceholderRowExec    │ |
|               | └───────────────────────────┘ |
|               |                               |
+---------------+-------------------------------+

https://datafusion.apache.org/user-guide/sql/explain.html

milenkovicm avatar May 01 '26 09:05 milenkovicm

@danielhumanmod current datafusion behaviour

> explain format indent select 1;
+---------------+--------------------------------------+
| plan_type     | plan                                 |
+---------------+--------------------------------------+
| logical_plan  | Projection: Int64(1)                 |
|               |   EmptyRelation: rows=1              |
| physical_plan | ProjectionExec: expr=[1 as Int64(1)] |
|               |   PlaceholderRowExec                 |
|               |                                      |
+---------------+--------------------------------------+
2 row(s) fetched.
Elapsed 0.003 seconds.

> explain select 1;
+---------------+-------------------------------+
| plan_type     | plan                          |
+---------------+-------------------------------+
| physical_plan | ┌───────────────────────────┐ |
|               | │       ProjectionExec      │ |
|               | │    --------------------   │ |
|               | │        Int64(1): 1        │ |
|               | └─────────────┬─────────────┘ |
|               | ┌─────────────┴─────────────┐ |
|               | │     PlaceholderRowExec    │ |
|               | └───────────────────────────┘ |
|               |                               |
+---------------+-------------------------------+

https://datafusion.apache.org/user-guide/sql/explain.html

thanks for the information, very helpful. Didn't catch this doc at the first place🙏

danielhumanmod avatar May 01 '26 20:05 danielhumanmod

Hey @milenkovicm when I was working on this, I realize that DF side missed the proto support for format field, we can adopt some workaround on our end, but maybe add support on DF will be better in the long run. Make a draft PR for this https://github.com/apache/datafusion/pull/21994, appreciate if you could take a look when you have time, thanks!

danielhumanmod avatar May 03 '26 07:05 danielhumanmod

https://github.com/apache/datafusion/pull/21768 more things coming to EXPLAIN cc @danielhumanmod

milenkovicm avatar May 11 '26 21:05 milenkovicm

Is there anything more to be done here ?

martin-g avatar May 18 '26 11:05 martin-g

Yes, there is part needed on plans which can't be done before df 54

milenkovicm avatar May 18 '26 11:05 milenkovicm

I think now that we cut the release branch we can make some breaking changes to the proto if needed?

adriangb avatar May 28 '26 15:05 adriangb

please do @adriangb, its related to #21768 , is it ?

milenkovicm avatar May 28 '26 15:05 milenkovicm

closing as done

milenkovicm avatar Nov 17 '26 21:11 milenkovicm