Open
Description
Describe the bug
Original issue from datafusion repository: apache/datafusion#9319
Error when doing explain directly in SQL.
To Reproduce
Using latest available version on Pypi (35.0.0)
>>> import datafusion
>>> ctx = datafusion.SessionContext()
>>> ctx.sql("explain select 1")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
Exception: Internal error: Unsupported logical plan: Explain must be root of the plan.
This was likely caused by a bug in DataFusion's code and we would welcome that you file an bug report in our issue tracker
Expected behavior
The ctx.sql("explain select 1")
should ideally succeed, as it works in regular DataFusion:
let ctx = SessionContext::new();
let df = ctx.sql("explain select 1").await?;
df.show().await?;
Will output:
+---------------+--------------------------------------+
| plan_type | plan |
+---------------+--------------------------------------+
| logical_plan | Projection: Int64(1) |
| | EmptyRelation |
| physical_plan | ProjectionExec: expr=[1 as Int64(1)] |
| | PlaceholderRowExec |
| | |
+---------------+--------------------------------------+
Additional context
Although the more correct way would be to do ctx.sql("select 1").explain()
, ctx.sql("explain select 1")
itself is technically still valid, so maybe something weird is going on here?