Skip to content

Conversation

@jayzhan211
Copy link
Contributor

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?

Signed-off-by: jayzhan211 <jayzhan211@gmail.com>
@github-actions github-actions bot added sql SQL Planner logical-expr Logical plan and expressions core Core DataFusion crate labels Jul 16, 2024
Signed-off-by: jayzhan211 <jayzhan211@gmail.com>
@github-actions github-actions bot added the optimizer Optimizer rules label Jul 16, 2024
@jayzhan211 jayzhan211 marked this pull request as ready for review July 16, 2024 01:16
@jayzhan211 jayzhan211 marked this pull request as draft July 16, 2024 01:20
@jayzhan211 jayzhan211 marked this pull request as ready for review July 16, 2024 01:23
@jayzhan211
Copy link
Contributor Author

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 {
Copy link
Contributor Author

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

Copy link
Contributor

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

Copy link
Contributor

@alamb alamb left a 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
Copy link
Contributor

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 {
Copy link
Contributor

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

}

/// Getter for expr planners
fn get_expr_planners(&self) -> Vec<Arc<dyn ExprPlanner>>;
Copy link
Contributor

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

Suggested change
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

Copy link
Member

@wjones127 wjones127 left a 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
@github-actions github-actions bot removed the optimizer Optimizer rules label Jul 17, 2024
Signed-off-by: jayzhan211 <jayzhan211@gmail.com>

impl<'a> ContextProvider for SessionContextProvider<'a> {
fn get_expr_planners(&self) -> &[Arc<dyn ExprPlanner>] {
&self.state.expr_planners
Copy link
Contributor Author

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

Copy link
Contributor

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 <jayzhan211@gmail.com>

impl<'a> ContextProvider for SessionContextProvider<'a> {
fn get_expr_planners(&self) -> &[Arc<dyn ExprPlanner>] {
&self.state.expr_planners
Copy link
Contributor

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 👌

@alamb alamb merged commit de0765a into apache:main Jul 17, 2024
@alamb
Copy link
Contributor

alamb commented Jul 17, 2024

Thanks @jayzhan211 and @wjones127

xinlifoobar pushed a commit to xinlifoobar/datafusion that referenced this pull request Jul 17, 2024
* 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>
xinlifoobar pushed a commit to xinlifoobar/datafusion that referenced this pull request Jul 18, 2024
* 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>
Lordworms pushed a commit to Lordworms/arrow-datafusion that referenced this pull request Jul 23, 2024
* 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>
wiedld pushed a commit to influxdata/arrow-datafusion that referenced this pull request Jul 31, 2024
* 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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

core Core DataFusion crate logical-expr Logical plan and expressions sql SQL Planner

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ExprPlanner not propagated to SqlToRel

3 participants