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

fix: Support Utf8View in numeric_string_coercion #13366

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
89 changes: 88 additions & 1 deletion datafusion/expr-common/src/type_coercion/binary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1127,7 +1127,8 @@ fn regex_comparison_string_coercion(
fn numeric_string_coercion(lhs_type: &DataType, rhs_type: &DataType) -> Option<DataType> {
use arrow::datatypes::DataType::*;
match (lhs_type, rhs_type) {
(Utf8 | LargeUtf8, other_type) | (other_type, Utf8 | LargeUtf8)
(Utf8 | Utf8View | LargeUtf8, other_type)
| (other_type, Utf8 | Utf8View | LargeUtf8)
if other_type.is_numeric() =>
{
Some(other_type.clone())
Expand Down Expand Up @@ -1490,6 +1491,92 @@ mod tests {
);
}

#[test]
fn test_numeric_string_coercion_with_utf8view() {
assert_eq!(
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you find a test case that fail if the change is reverted instead of the rust test here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There are no test cases that will fail if changes are reverted other than this one.

Copy link
Contributor

@jayzhan211 jayzhan211 Nov 12, 2024

Choose a reason for hiding this comment

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

so it means the change is not solving the problem 🤔 maybe this function is not used anywhere?

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'm a bit confused, the function is used here. If reverted, the change will fail the current added test but no other tests. This means that the changes allow support for Utf8View in numeric_string_conversion

Copy link
Contributor

@jayzhan211 jayzhan211 Nov 12, 2024

Choose a reason for hiding this comment

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

If I understand correctly, your test is unit test, it failed if the change reverted but it doesn't mean the change effects the actual query (I guess after we change the signature for most of the function, numeric string coercion might not be used at all). I suggest we add end2end test (slt) instead of unit test

Copy link
Contributor

Choose a reason for hiding this comment

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

Ideally this query should pass after your change, but it didn't

SELECT make_array(arrow_cast('1.2', 'Utf8View'), 2.3);

numeric_string_coercion(&DataType::Utf8View, &DataType::Int8),
Some(DataType::Int8)
);
assert_eq!(
numeric_string_coercion(&DataType::Int8, &DataType::Utf8View),
Some(DataType::Int8)
);
assert_eq!(
numeric_string_coercion(&DataType::Utf8View, &DataType::Int16),
Some(DataType::Int16)
);
assert_eq!(
numeric_string_coercion(&DataType::Int16, &DataType::Utf8View),
Some(DataType::Int16)
);
assert_eq!(
numeric_string_coercion(&DataType::Utf8View, &DataType::Int32),
Some(DataType::Int32)
);
assert_eq!(
numeric_string_coercion(&DataType::Int32, &DataType::Utf8View),
Some(DataType::Int32)
);
assert_eq!(
numeric_string_coercion(&DataType::Utf8View, &DataType::Int64),
Some(DataType::Int64)
);
assert_eq!(
numeric_string_coercion(&DataType::Int64, &DataType::Utf8View),
Some(DataType::Int64)
);
assert_eq!(
numeric_string_coercion(&DataType::Utf8View, &DataType::Float32),
Some(DataType::Float32)
);
assert_eq!(
numeric_string_coercion(&DataType::Float32, &DataType::Utf8View),
Some(DataType::Float32)
);
assert_eq!(
numeric_string_coercion(&DataType::Utf8View, &DataType::Float64),
Some(DataType::Float64)
);
assert_eq!(
numeric_string_coercion(&DataType::Float64, &DataType::Utf8View),
Some(DataType::Float64)
);

// should return `None`, it doesn't match the expected `string` <=> `numeric`
assert_eq!(
numeric_string_coercion(&DataType::Utf8View, &DataType::LargeUtf8),
None
);
assert_eq!(
numeric_string_coercion(&DataType::LargeUtf8, &DataType::Utf8View),
None
);
assert_eq!(
numeric_string_coercion(&DataType::Utf8View, &DataType::Boolean),
None
);
assert_eq!(
numeric_string_coercion(&DataType::Boolean, &DataType::Utf8View),
None
);
assert_eq!(
numeric_string_coercion(&DataType::Utf8View, &DataType::Utf8),
None
);
assert_eq!(
numeric_string_coercion(&DataType::Utf8, &DataType::Utf8View),
None
);
assert_eq!(
numeric_string_coercion(&DataType::Utf8View, &DataType::Null),
None
);
assert_eq!(
numeric_string_coercion(&DataType::Null, &DataType::Utf8View),
None
);
}

#[test]
fn test_dictionary_type_coercion() {
use DataType::*;
Expand Down
Loading