Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

minor: do not fail analyzer if subquery plan contains extension #7455

Merged
merged 2 commits into from
Sep 6, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I recommend putting this test somewhere in https://github.com/apache/arrow-datafusion/tree/main/datafusion/core/tests/user_defined (mostly so it is easier to find and to ensure everything is working as expected)

I think you may be able to reuse the dummy user defined code there

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great suggestion. I plan to cover this case in datafusion/core/tests/user_defined/user_defined_plan.rs. But since the previous TopK is based on optimizer, I may need to add another extension plan and an analyzer rule.

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();
}
}