Skip to content

Commit

Permalink
minor: do not fail analyzer if subquery plan contains extension (#7455)
Browse files Browse the repository at this point in the history
* do not fail analyzer if subquery plan contains extension

Signed-off-by: Ruihang Xia <[email protected]>

* add a simple UT case

Signed-off-by: Ruihang Xia <[email protected]>

---------

Signed-off-by: Ruihang Xia <[email protected]>
  • Loading branch information
waynexia authored Sep 6, 2023
1 parent dfad0af commit 4e33be5
Showing 1 changed file with 55 additions and 0 deletions.
55 changes: 55 additions & 0 deletions datafusion/optimizer/src/analyzer/subquery.rs
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@ fn check_inner_plan(
Ok(())
}
},
LogicalPlan::Extension(_) => Ok(()),
_ => plan_err!("Unsupported operator in the subquery plan."),
}
}
Expand Down Expand Up @@ -338,3 +339,57 @@ fn check_mixed_out_refer_in_window(window: &Window) -> Result<()> {
Ok(())
}
}

#[cfg(test)]
mod test {
use std::sync::Arc;

use datafusion_common::{DFSchema, DFSchemaRef};
use datafusion_expr::{Extension, UserDefinedLogicalNodeCore};

use super::*;

#[derive(Debug, PartialEq, Eq, Hash)]
struct MockUserDefinedLogicalPlan {
empty_schema: DFSchemaRef,
}

impl UserDefinedLogicalNodeCore for MockUserDefinedLogicalPlan {
fn name(&self) -> &str {
"MockUserDefinedLogicalPlan"
}

fn inputs(&self) -> Vec<&LogicalPlan> {
vec![]
}

fn schema(&self) -> &datafusion_common::DFSchemaRef {
&self.empty_schema
}

fn expressions(&self) -> Vec<Expr> {
vec![]
}

fn fmt_for_explain(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
write!(f, "MockUserDefinedLogicalPlan")
}

fn from_template(&self, _exprs: &[Expr], _inputs: &[LogicalPlan]) -> Self {
Self {
empty_schema: self.empty_schema.clone(),
}
}
}

#[test]
fn wont_fail_extension_plan() {
let plan = LogicalPlan::Extension(Extension {
node: Arc::new(MockUserDefinedLogicalPlan {
empty_schema: DFSchemaRef::new(DFSchema::empty()),
}),
});

check_inner_plan(&plan, false, false, true).unwrap();
}
}

0 comments on commit 4e33be5

Please sign in to comment.