-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Get expr planners when creating new planner #11485
Conversation
Signed-off-by: jayzhan211 <[email protected]>
Signed-off-by: jayzhan211 <[email protected]>
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 <[email protected]>
@@ -196,12 +193,6 @@ impl<'a, S: ContextProvider> SqlToRel<'a, S> { | |||
Self::new_with_options(context_provider, ParserOptions::default()) | |||
} | |||
|
|||
/// 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
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))
@@ -186,8 +185,6 @@ pub struct SqlToRel<'a, S: ContextProvider> { | |||
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.
👍
@@ -196,12 +193,6 @@ impl<'a, S: ContextProvider> SqlToRel<'a, S> { | |||
Self::new_with_options(context_provider, ParserOptions::default()) | |||
} | |||
|
|||
/// 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
@@ -60,6 +60,9 @@ pub trait ContextProvider { | |||
not_impl_err!("Recursive CTE is not implemented") | |||
} | |||
|
|||
/// 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
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
Signed-off-by: jayzhan211 <[email protected]>
struct SessionContextProvider<'a> { | ||
state: &'a SessionState, | ||
tables: HashMap<String, Arc<dyn TableSource>>, | ||
} | ||
|
||
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 👌
Signed-off-by: jayzhan211 <[email protected]>
struct SessionContextProvider<'a> { | ||
state: &'a SessionState, | ||
tables: HashMap<String, Arc<dyn TableSource>>, | ||
} | ||
|
||
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 <[email protected]> * get expr planner when creating planner Signed-off-by: jayzhan211 <[email protected]> * no planners in sqltorel Signed-off-by: jayzhan211 <[email protected]> * Add docs about SessionContextProvider * Use Slice rather than Vec to access expr planners * add test Signed-off-by: jayzhan211 <[email protected]> * clippy Signed-off-by: jayzhan211 <[email protected]> --------- Signed-off-by: jayzhan211 <[email protected]> Co-authored-by: Andrew Lamb <[email protected]>
* get expr planners when creating new planner Signed-off-by: jayzhan211 <[email protected]> * get expr planner when creating planner Signed-off-by: jayzhan211 <[email protected]> * no planners in sqltorel Signed-off-by: jayzhan211 <[email protected]> * Add docs about SessionContextProvider * Use Slice rather than Vec to access expr planners * add test Signed-off-by: jayzhan211 <[email protected]> * clippy Signed-off-by: jayzhan211 <[email protected]> --------- Signed-off-by: jayzhan211 <[email protected]> Co-authored-by: Andrew Lamb <[email protected]>
* get expr planners when creating new planner Signed-off-by: jayzhan211 <[email protected]> * get expr planner when creating planner Signed-off-by: jayzhan211 <[email protected]> * no planners in sqltorel Signed-off-by: jayzhan211 <[email protected]> * Add docs about SessionContextProvider * Use Slice rather than Vec to access expr planners * add test Signed-off-by: jayzhan211 <[email protected]> * clippy Signed-off-by: jayzhan211 <[email protected]> --------- Signed-off-by: jayzhan211 <[email protected]> Co-authored-by: Andrew Lamb <[email protected]>
* get expr planners when creating new planner Signed-off-by: jayzhan211 <[email protected]> * get expr planner when creating planner Signed-off-by: jayzhan211 <[email protected]> * no planners in sqltorel Signed-off-by: jayzhan211 <[email protected]> * Add docs about SessionContextProvider * Use Slice rather than Vec to access expr planners * add test Signed-off-by: jayzhan211 <[email protected]> * clippy Signed-off-by: jayzhan211 <[email protected]> --------- Signed-off-by: jayzhan211 <[email protected]> Co-authored-by: Andrew Lamb <[email protected]>
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?