-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Get expr planners when creating new planner #11485
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
Conversation
Signed-off-by: jayzhan211 <jayzhan211@gmail.com>
Signed-off-by: jayzhan211 <jayzhan211@gmail.com>
|
We may even remove planners in SqlToRel 🤔 ? /// SQL query planner
pub struct SqlToRel<'a, S: ContextProvider> {
pub(crate) context_provider: &'a S,
pub(crate) options: ParserOptions,
pub(crate) normalizer: IdentNormalizer,
/// user defined planner extensions
pub(crate) planners: Vec<Arc<dyn ExprPlanner>>,
} |
Signed-off-by: jayzhan211 <jayzhan211@gmail.com>
| } | ||
|
|
||
| /// add an user defined planner | ||
| pub fn with_user_defined_planner(mut self, planner: Arc<dyn ExprPlanner>) -> Self { |
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.
I think we can register planner in session state
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.
I think it makes sense to use the underlying session state as the source of truth
alamb
left a comment
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 @jayzhan211 this makes sense to me.
I have a suggestion to avoid creating Vec's for all accesses to extension planners. Let me know what you think: jayzhan211#3
I also wonder if we should add a test case to avoid this kind of issue from happening again (whatever API Lance and Delta.rs are using clearly isn't covered by our existing tests)
cc @wjones127 and @rtyler (who also mentioned this #11180 (comment))
| pub(crate) context_provider: &'a S, | ||
| pub(crate) options: ParserOptions, | ||
| pub(crate) normalizer: IdentNormalizer, | ||
| /// user defined planner extensions |
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.
👍
| } | ||
|
|
||
| /// add an user defined planner | ||
| pub fn with_user_defined_planner(mut self, planner: Arc<dyn ExprPlanner>) -> Self { |
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.
I think it makes sense to use the underlying session state as the source of truth
datafusion/expr/src/planner.rs
Outdated
| } | ||
|
|
||
| /// Getter for expr planners | ||
| fn get_expr_planners(&self) -> Vec<Arc<dyn ExprPlanner>>; |
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.
I spent some time trying to figure out if we could avoid this Vec cloning all the time -- with
| fn get_expr_planners(&self) -> Vec<Arc<dyn ExprPlanner>>; | |
| fn get_expr_planners(&self) -> &[Arc<dyn ExprPlanner>] {&[]} |
I think this is possible -- I made jayzhan211#3 to show how it looks
wjones127
left a comment
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. This seems like a good simplification. I also agree that we could make get_expr_planners return a slice.
Use Slice rather than Vec to access expr planners
|
|
||
| impl<'a> ContextProvider for SessionContextProvider<'a> { | ||
| fn get_expr_planners(&self) -> &[Arc<dyn ExprPlanner>] { | ||
| &self.state.expr_planners |
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.
I remove expr_planners field in SessionContextProvider and get it from state directly
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.
Nice! I tried to figure out how to do this previously and got confused about a lock or something. This is very nice 👌
|
|
||
| impl<'a> ContextProvider for SessionContextProvider<'a> { | ||
| fn get_expr_planners(&self) -> &[Arc<dyn ExprPlanner>] { | ||
| &self.state.expr_planners |
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.
Nice! I tried to figure out how to do this previously and got confused about a lock or something. This is very nice 👌
|
Thanks @jayzhan211 and @wjones127 |
* get expr planners when creating new planner Signed-off-by: jayzhan211 <jayzhan211@gmail.com> * get expr planner when creating planner Signed-off-by: jayzhan211 <jayzhan211@gmail.com> * no planners in sqltorel Signed-off-by: jayzhan211 <jayzhan211@gmail.com> * Add docs about SessionContextProvider * Use Slice rather than Vec to access expr planners * add test Signed-off-by: jayzhan211 <jayzhan211@gmail.com> * clippy Signed-off-by: jayzhan211 <jayzhan211@gmail.com> --------- Signed-off-by: jayzhan211 <jayzhan211@gmail.com> Co-authored-by: Andrew Lamb <andrew@nerdnetworks.org>
* get expr planners when creating new planner Signed-off-by: jayzhan211 <jayzhan211@gmail.com> * get expr planner when creating planner Signed-off-by: jayzhan211 <jayzhan211@gmail.com> * no planners in sqltorel Signed-off-by: jayzhan211 <jayzhan211@gmail.com> * Add docs about SessionContextProvider * Use Slice rather than Vec to access expr planners * add test Signed-off-by: jayzhan211 <jayzhan211@gmail.com> * clippy Signed-off-by: jayzhan211 <jayzhan211@gmail.com> --------- Signed-off-by: jayzhan211 <jayzhan211@gmail.com> Co-authored-by: Andrew Lamb <andrew@nerdnetworks.org>
* get expr planners when creating new planner Signed-off-by: jayzhan211 <jayzhan211@gmail.com> * get expr planner when creating planner Signed-off-by: jayzhan211 <jayzhan211@gmail.com> * no planners in sqltorel Signed-off-by: jayzhan211 <jayzhan211@gmail.com> * Add docs about SessionContextProvider * Use Slice rather than Vec to access expr planners * add test Signed-off-by: jayzhan211 <jayzhan211@gmail.com> * clippy Signed-off-by: jayzhan211 <jayzhan211@gmail.com> --------- Signed-off-by: jayzhan211 <jayzhan211@gmail.com> Co-authored-by: Andrew Lamb <andrew@nerdnetworks.org>
* get expr planners when creating new planner Signed-off-by: jayzhan211 <jayzhan211@gmail.com> * get expr planner when creating planner Signed-off-by: jayzhan211 <jayzhan211@gmail.com> * no planners in sqltorel Signed-off-by: jayzhan211 <jayzhan211@gmail.com> * Add docs about SessionContextProvider * Use Slice rather than Vec to access expr planners * add test Signed-off-by: jayzhan211 <jayzhan211@gmail.com> * clippy Signed-off-by: jayzhan211 <jayzhan211@gmail.com> --------- Signed-off-by: jayzhan211 <jayzhan211@gmail.com> Co-authored-by: Andrew Lamb <andrew@nerdnetworks.org>
Which issue does this PR close?
Closes #11477 .
Rationale for this change
What changes are included in this PR?
Are these changes tested?
Are there any user-facing changes?