-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Allow user defined SQL planners to be registered #11208
Allow user defined SQL planners to be registered #11208
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you @samuelcolvin -- this looks great to me
cc @jayzhan211
@@ -99,6 +100,8 @@ pub struct SessionState { | |||
session_id: String, | |||
/// Responsible for analyzing and rewrite a logical plan before optimization | |||
analyzer: Analyzer, | |||
/// Provides support for customising the SQL planner, e.g. to add support for custom operators like `->>` or `?` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
use datafusion_expr::planner::{PlannerResult, RawBinaryExpr, UserDefinedSQLPlanner}; | ||
use datafusion_expr::BinaryExpr; | ||
|
||
struct MyCustomPlanner; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
❤️
expr: RawBinaryExpr, | ||
_schema: &DFSchema, | ||
) -> Result<PlannerResult<RawBinaryExpr>> { | ||
match &expr.op { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is awesome
|
||
struct MyCustomPlanner; | ||
|
||
impl UserDefinedSQLPlanner for MyCustomPlanner { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
impl UserDefinedSQLPlanner for MyCustomPlanner { | |
/// Planner that plans `->` and `-->` specially | |
impl UserDefinedSQLPlanner for MyCustomPlanner { |
// custom planners are registered first, so they're run first and take precedence over built-in planners | ||
for planner in self.user_defined_sql_planners.iter() { | ||
query = query.with_user_defined_planner(planner.clone()); | ||
} | ||
|
||
// register crate of array expressions (if enabled) | ||
#[cfg(feature = "array_expressions")] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It might make sense to move the registering of these planners into the constructor of SessionState rather than here (so users could potentially more carefully control the planner content). But we can do that as a follow on PR
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
Thanks @samuelcolvin and @alamb
* Allow user defined SQL planners to be registered * fix clippy, remove unused Default * format
Rationale for this change
Follow up to #11180 that allows
UserDefinedSQLPlanner
s to be registered onFunctionRegistry
s, mostly copied from #11137.Are these changes tested?
Yes, I've added a test
Are there any user-facing changes?
Adds
FunctionRegistry::register_user_defined_sql_planner
.