Skip to content

Apache DataFusion SQL Query Engine

fix: throw error when incursion happen in dataframe api (#9330)

Lordwormsff36f6d99285
diff --git a/datafusion/core/src/dataframe/mod.rs b/datafusion/core/src/dataframe/mod.rs
index e407c477ae..3a60d57f66 100644
--- a/datafusion/core/src/dataframe/mod.rs
+++ b/datafusion/core/src/dataframe/mod.rs
@@ -49,8 +49,8 @@ use datafusion_common::file_options::csv_writer::CsvWriterOptions;
use datafusion_common::file_options::json_writer::JsonWriterOptions;
use datafusion_common::parsers::CompressionTypeVariant;
use datafusion_common::{
- Column, DFSchema, DataFusionError, FileType, FileTypeWriterOptions, ParamValues,
- SchemaError, UnnestOptions,
+ plan_err, Column, DFSchema, DataFusionError, FileType, FileTypeWriterOptions,
+ ParamValues, SchemaError, UnnestOptions,
};
use datafusion_expr::dml::CopyOptions;
use datafusion_expr::{
@@ -1044,6 +1044,9 @@ impl DataFrame {
/// # }
/// ```
pub fn explain(self, verbose: bool, analyze: bool) -> Result<DataFrame> {
+ if matches!(self.plan, LogicalPlan::Explain(_)) {
+ return plan_err!("Nested EXPLAINs are not supported");
+ }
let plan = LogicalPlanBuilder::from(self.plan)
.explain(verbose, analyze)?
.build()?;
@@ -2975,4 +2978,15 @@ mod tests {
Ok(())
}
+ #[tokio::test]
+ async fn nested_explain_should_fail() -> Result<()> {
+ let ctx = SessionContext::new();
+ // must be error
+ let mut result = ctx.sql("explain select 1").await?.explain(false, false);
+ assert!(result.is_err());
+ // must be error
+ result = ctx.sql("explain explain select 1").await;
+ assert!(result.is_err());
+ Ok(())
+ }
}