-
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
feat: Support Utf8View
for get_wider_type
+ binary_to_string_coercion
functions
#13370
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -834,14 +834,16 @@ pub fn get_wider_type(lhs: &DataType, rhs: &DataType) -> Result<DataType> { | |
use arrow::datatypes::DataType::*; | ||
Ok(match (lhs, rhs) { | ||
(lhs, rhs) if lhs == rhs => lhs.clone(), | ||
// Either Utf8View + Utf8 will return Utf8View | ||
(Utf8View, Utf8) | (Utf8, Utf8View) => Utf8View, | ||
// Right UInt is larger than left UInt. | ||
(UInt8, UInt16 | UInt32 | UInt64) | (UInt16, UInt32 | UInt64) | (UInt32, UInt64) | | ||
// Right Int is larger than left Int. | ||
(Int8, Int16 | Int32 | Int64) | (Int16, Int32 | Int64) | (Int32, Int64) | | ||
// Right Float is larger than left Float. | ||
(Float16, Float32 | Float64) | (Float32, Float64) | | ||
// Right String is larger than left String. | ||
(Utf8, LargeUtf8) | | ||
(Utf8 | Utf8View, LargeUtf8) | | ||
// Any right type is wider than a left hand side Null. | ||
(Null, _) => rhs.clone(), | ||
// Left UInt is larger than right UInt. | ||
|
@@ -851,7 +853,7 @@ pub fn get_wider_type(lhs: &DataType, rhs: &DataType) -> Result<DataType> { | |
// Left Float is larger than right Float. | ||
(Float32 | Float64, Float16) | (Float64, Float32) | | ||
// Left String is larger than right String. | ||
(LargeUtf8, Utf8) | | ||
(LargeUtf8, Utf8 | Utf8View) | | ||
// Any left type is wider than a right hand side Null. | ||
(_, Null) => lhs.clone(), | ||
(List(lhs_field), List(rhs_field)) => { | ||
|
@@ -1172,16 +1174,22 @@ fn binary_to_string_coercion( | |
match (lhs_type, rhs_type) { | ||
(Binary, Utf8) => Some(Utf8), | ||
(Binary, LargeUtf8) => Some(LargeUtf8), | ||
(Binary, Utf8View) => Some(Utf8View), | ||
(BinaryView, Utf8) => Some(Utf8View), | ||
(BinaryView, LargeUtf8) => Some(LargeUtf8), | ||
(BinaryView, Utf8View) => Some(Utf8View), | ||
(LargeBinary, Utf8) => Some(LargeUtf8), | ||
(LargeBinary, LargeUtf8) => Some(LargeUtf8), | ||
(LargeBinary, Utf8View) => Some(LargeUtf8), | ||
(Utf8, Binary) => Some(Utf8), | ||
(Utf8, LargeBinary) => Some(LargeUtf8), | ||
(Utf8, BinaryView) => Some(Utf8View), | ||
(LargeUtf8, Binary) => Some(LargeUtf8), | ||
(LargeUtf8, LargeBinary) => Some(LargeUtf8), | ||
(LargeUtf8, BinaryView) => Some(LargeUtf8), | ||
(Utf8View, Binary) => Some(Utf8View), | ||
(Utf8View, LargeBinary) => Some(LargeUtf8), | ||
(Utf8View, BinaryView) => Some(Utf8View), | ||
_ => None, | ||
} | ||
} | ||
|
@@ -1544,6 +1552,59 @@ mod tests { | |
); | ||
} | ||
|
||
#[test] | ||
fn test_get_wider_type_with_utf8view() { | ||
assert_eq!( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not this kind of test, but a valid sql query that goes through the coercion function There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @jayzhan211 Correct me if I'm wrong, but this seems to be a problem with arrow casting from numerics to utf8view, the same can be said for this, #13366. However correct me if I'm wrong, I can't seem to find a sql query that triggers it, although i believe there should be one There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It seems only There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I mean There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
get_wider_type(&DataType::Utf8View, &DataType::Utf8View).unwrap(), | ||
DataType::Utf8View | ||
); | ||
|
||
assert_eq!( | ||
get_wider_type(&DataType::Utf8View, &DataType::Utf8).unwrap(), | ||
DataType::Utf8View | ||
); | ||
|
||
assert_eq!( | ||
get_wider_type(&DataType::Utf8View, &DataType::LargeUtf8).unwrap(), | ||
DataType::LargeUtf8 | ||
); | ||
|
||
assert_eq!( | ||
get_wider_type(&DataType::Utf8View, &DataType::Null).unwrap(), | ||
DataType::Utf8View | ||
); | ||
|
||
assert!(get_wider_type(&DataType::Utf8View, &DataType::Int32).is_err()); | ||
} | ||
|
||
#[test] | ||
fn test_binary_to_string_coercion_with_utf8view() { | ||
assert_eq!( | ||
binary_to_string_coercion(&DataType::Binary, &DataType::Utf8View), | ||
Some(DataType::Utf8View) | ||
); | ||
assert_eq!( | ||
binary_to_string_coercion(&DataType::Utf8View, &DataType::Binary), | ||
Some(DataType::Utf8View) | ||
); | ||
assert_eq!( | ||
binary_to_string_coercion(&DataType::BinaryView, &DataType::Utf8View), | ||
Some(DataType::Utf8View) | ||
); | ||
assert_eq!( | ||
binary_to_string_coercion(&DataType::Utf8View, &DataType::LargeBinary), | ||
Some(DataType::LargeUtf8) | ||
); | ||
assert_eq!( | ||
binary_to_string_coercion(&DataType::LargeBinary, &DataType::Utf8View), | ||
Some(DataType::LargeUtf8) | ||
); | ||
assert_eq!( | ||
binary_to_string_coercion(&DataType::Utf8View, &DataType::Int32), | ||
None | ||
); | ||
} | ||
|
||
/// Test coercion rules for binary operators | ||
/// | ||
/// Applies coercion rules for `$LHS_TYPE $OP $RHS_TYPE` and asserts that the | ||
|
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.
These rules would allow running
binary like utf8view
-- do we have a usecase for that? We could write tests for it, but I don't think it would be widely used 🤔