datafusion icon indicating copy to clipboard operation
datafusion copied to clipboard

Nested explain possible via DataFrame API

Open Jefffrey opened this issue 1 year ago • 1 comments

Describe the bug

Via SQL we disallow nested explains:

use datafusion::error::Result;
use datafusion::prelude::*;

#[tokio::main]
async fn main() -> Result<()> {
    let ctx = SessionContext::new();

    ctx.sql("explain explain select 1").await?.show().await?;

    Ok(())
}

Will output:

Error: Plan("Nested EXPLAINs are not supported")

This is expected behaviour.

However, via the DataFrame API we can bypass this restriction.

To Reproduce

use datafusion::error::Result;
use datafusion::prelude::*;

#[tokio::main]
async fn main() -> Result<()> {
    let ctx = SessionContext::new();

    ctx.sql("explain select 1")
        .await?
        .explain(false, false)? // NOTE: you can actually just keep adding more explains here
        .show()
        .await?;

    Ok(())
}

Will output:

+--------------+------------------------+
| plan_type    | plan                   |
+--------------+------------------------+
| logical_plan | Explain                |
|              |   Projection: Int64(1) |
|              |     EmptyRelation      |
+--------------+------------------------+

Expected behavior

DataFrame API version should throw an error like for SQL

Additional context

No response

Jefffrey avatar Feb 23 '24 21:02 Jefffrey

take

Lordworms avatar Feb 23 '24 23:02 Lordworms