alamb commented on code in PR #8871:
URL: https://github.com/apache/arrow-rs/pull/8871#discussion_r2543061254
##########
arrow-cast/src/cast/mod.rs:
##########
@@ -221,12 +221,34 @@ pub fn can_cast_types(from_type: &DataType, to_type:
&DataType) -> bool {
Decimal32(_, _) | Decimal64(_, _) | Decimal128(_, _) |
Decimal256(_, _),
) => true,
(Struct(from_fields), Struct(to_fields)) => {
- from_fields.len() == to_fields.len()
- && from_fields.iter().zip(to_fields.iter()).all(|(f1, f2)| {
+ if from_fields.len() != to_fields.len() {
+ return false;
+ }
+
+ // fast path, all field names are in the same order and same
number of fields
+ if from_fields
+ .iter()
+ .zip(to_fields.iter())
+ .all(|(f1, f2)| f1.name() == f2.name())
+ {
+ return from_fields.iter().zip(to_fields.iter()).all(|(f1, f2)|
{
// Assume that nullability between two structs are
compatible, if not,
// cast kernel will return error.
can_cast_types(f1.data_type(), f2.data_type())
- })
+ });
+ }
+
+ // slow path, we match the fields by name
Review Comment:
I think one idea that has come up in the past is to do this mapping
calculation once and then use it for both can_cast_types and cast
However, this seems to be strictly better than current main (doesn't slow
down existing code and allows more uses, so 👍 to me)
##########
arrow-cast/src/cast/mod.rs:
##########
@@ -10836,11 +10890,11 @@ mod tests {
let int = Arc::new(Int32Array::from(vec![42, 28, 19, 31]));
let struct_array = StructArray::from(vec![
(
- Arc::new(Field::new("b", DataType::Boolean, false)),
+ Arc::new(Field::new("a", DataType::Boolean, false)),
Review Comment:
why this change?
##########
arrow-cast/src/cast/mod.rs:
##########
@@ -10884,11 +10938,11 @@ mod tests {
let int = Arc::new(Int32Array::from(vec![Some(42), None, Some(19),
None]));
let struct_array = StructArray::from(vec![
(
- Arc::new(Field::new("b", DataType::Boolean, false)),
+ Arc::new(Field::new("a", DataType::Boolean, false)),
Review Comment:
likewise why was this test changed?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]