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

Introduce TypePlanner for customizing type planning #13294

Merged
merged 3 commits into from
Nov 13, 2024

Conversation

goldmedal
Copy link
Contributor

@goldmedal goldmedal commented Nov 7, 2024

Which issue does this PR close?

Closes #13292 .

Rationale for this change

What changes are included in this PR?

Are these changes tested?

yes

Are there any user-facing changes?

A new trait for ExprPlanner

@github-actions github-actions bot added sql SQL Planner logical-expr Logical plan and expressions labels Nov 7, 2024
@goldmedal goldmedal marked this pull request as ready for review November 7, 2024 15:34
/// Plan SQL type to DataFusion data type
///
/// Returns None if not possible
fn plan_data_type(&self, _sql_type: &ast::DataType) -> Result<Option<DataType>> {
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

@@ -401,6 +401,14 @@ impl<'a, S: ContextProvider> SqlToRel<'a, S> {
}

pub(crate) fn convert_data_type(&self, sql_type: &SQLDataType) -> Result<DataType> {
// First check if any of the registered expr_planners can handle this type
for expr_planner in self.context_provider.get_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.

It seems strange that the planner for individual expressions would handle query-wide data types (though I realize this is currently the only hook that is available into the sql planner)

What would you think about adding a DataTypePlanner trait / field to the planner explicitly for this conversion?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

An independent trait looks good to me. I'm thinking what's a good way to register the custom planner.
Maybe introduce a method in ContextProvder::get_data_type_planner?

pub trait ContextProvider {
...
  fn get_data_type(&self) -> Option<Arc<dyn DataTypePlanner>>
      None
  }
}

We can allow registering the data type planner in SessionState. WDYT?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes I think that makes sense to me

@github-actions github-actions bot added the core Core DataFusion crate label Nov 9, 2024
@goldmedal goldmedal changed the title introduce plan_data_type for ExprPlanner introduce TypePlanner for customizing type planning Nov 9, 2024
@goldmedal goldmedal changed the title introduce TypePlanner for customizing type planning Introduce TypePlanner for customizing type planning Nov 9, 2024
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.

Thank you @goldmedal -- this looks great

I apologize for the delay in reviewing. I have been away for a few days.

@goldmedal
Copy link
Contributor Author

Thank you @goldmedal -- this looks great

I apologize for the delay in reviewing. I have been away for a few days.

Never mind. Thanks @alamb for reviewing.

@goldmedal goldmedal merged commit 4e1f839 into apache:main Nov 13, 2024
25 checks passed
@goldmedal goldmedal deleted the feature/13292-custom-type-planning branch November 13, 2024 14:26
wiedld added a commit to influxdata/arrow-datafusion that referenced this pull request Jan 7, 2025
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.

Allow to customize convert_data_type behavior when SQL planning
2 participants