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

Consolidate coercion code in datafusion_expr::type_coercion and submodules #3728

Merged
merged 6 commits into from
Oct 6, 2022

Conversation

alamb
Copy link
Contributor

@alamb alamb commented Oct 5, 2022

Which issue does this PR close?

re #3582
re #3419

Rationale for this change

I want to continue the good work from @liukun4515 to get type coercion into a single place as part of the logical planning phase, as well as to prepare for the additional work described in #3419 by @andygrove

This PR just moves coercion code around, no functional change is intended

Note that I plan to make a public API for coercion shortly -- see #3708

What changes are included in this PR?

Move coercion code from various places that it was scattered around the codebase into `datafusion_expr::type_coercion and submodules

Are there any user-facing changes?

If anyone calls these functions directly, they will need to change how to find them

@github-actions github-actions bot added logical-expr Logical plan and expressions optimizer Optimizer rules physical-expr Physical Expressions labels Oct 5, 2022
use std::{fmt, str::FromStr};

pub static STRINGS: &[DataType] = &[DataType::Utf8, DataType::LargeUtf8];
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Moved to type_coercion/aggregate.rs

//! performed because all valid i32 values can be represented using an
//! i64. However, i64 -> i32 is never performed as there are i64
//! values which can not be represented by i32 values.
//!

use crate::{Signature, TypeSignature};
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Moved this code into Moved to type_coercion/function.rsas it is related to function coercion, despite thedata_types` generic name

Ok(())
}
}
pub mod aggregates;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Now the code for various coercion lives in a module that helps identify what it is for

@@ -421,30 +422,6 @@ fn coercion_decimal_mathematics_type(
}
}

/// Determine if a DataType is signed numeric or not
Copy link
Contributor Author

Choose a reason for hiding this comment

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

moved into type_coercion.rs as this is not specific to binary expressions

@@ -17,6 +17,7 @@

//! Coercion rules for matching argument types for binary operators
Copy link
Contributor Author

@alamb alamb Oct 5, 2022

Choose a reason for hiding this comment

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

I renamed binary_rule.rs to type_coercion/binary.rs to better explain what it is for. I have always been confused about the name binary_rule

I think this module has a lot more code than for binary operators so it can be split / cleaned up more but I felt this is a good start

@liukun4515
Copy link
Contributor

Thanks for your work @alamb
This is what i want to do too.

@alamb
Copy link
Contributor Author

alamb commented Oct 6, 2022

I am going to merge this PR quickly as it is blocking some of my other work I think it has the potential to gather conflicts and I think @liukun4515 is ok with the plan (even though he hasn't yet explicitly approved it). I am happy to make any changes in follow on PRs -- please just let me know

@alamb alamb merged commit 7c5c2e5 into apache:master Oct 6, 2022
@ursabot
Copy link

ursabot commented Oct 6, 2022

Benchmark runs are scheduled for baseline = 23682f6 and contender = 7c5c2e5. 7c5c2e5 is a master commit associated with this PR. Results will be available as each benchmark for each run completes.
Conbench compare runs links:
[Skipped ⚠️ Benchmarking of arrow-datafusion-commits is not supported on ec2-t3-xlarge-us-east-2] ec2-t3-xlarge-us-east-2
[Skipped ⚠️ Benchmarking of arrow-datafusion-commits is not supported on test-mac-arm] test-mac-arm
[Skipped ⚠️ Benchmarking of arrow-datafusion-commits is not supported on ursa-i9-9960x] ursa-i9-9960x
[Skipped ⚠️ Benchmarking of arrow-datafusion-commits is not supported on ursa-thinkcentre-m75q] ursa-thinkcentre-m75q
Buildkite builds:
Supported benchmarks:
ec2-t3-xlarge-us-east-2: Supported benchmark langs: Python, R. Runs only benchmarks with cloud = True
test-mac-arm: Supported benchmark langs: C++, Python, R
ursa-i9-9960x: Supported benchmark langs: Python, R, JavaScript
ursa-thinkcentre-m75q: Supported benchmark langs: C++, Java

@liukun4515
Copy link
Contributor

I am going to merge this PR quickly as it is blocking some of my other work I think it has the potential to gather conflicts and I think @liukun4515 is ok with the plan (even though he hasn't yet explicitly approved it). I am happy to make any changes in follow on PRs -- please just let me know

LGTM

@alamb alamb deleted the alamb/consoludate_coercion branch October 6, 2022 12:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
logical-expr Logical plan and expressions optimizer Optimizer rules physical-expr Physical Expressions
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants