This is an automated email from the ASF dual-hosted git repository.

alamb pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/arrow-rs.git


The following commit(s) were added to refs/heads/master by this push:
     new b882d45  Fix generate_interval_case in integration test (#1446)
b882d45 is described below

commit b882d4599d29197b3d41a91fac29cdb8702e8788
Author: Liang-Chi Hsieh <[email protected]>
AuthorDate: Thu Mar 17 05:45:56 2022 -0700

    Fix generate_interval_case in integration test (#1446)
    
    * Fix generate_interval_case
    
    * Fix
---
 arrow/src/compute/kernels/cast.rs | 32 ++++++++++++++++++++++++++++++++
 integration-testing/src/lib.rs    | 33 +++++++++++++++++++++++++++++++++
 2 files changed, 65 insertions(+)

diff --git a/arrow/src/compute/kernels/cast.rs 
b/arrow/src/compute/kernels/cast.rs
index 49a0837..0e9a275 100644
--- a/arrow/src/compute/kernels/cast.rs
+++ b/arrow/src/compute/kernels/cast.rs
@@ -228,6 +228,20 @@ pub fn can_cast_types(from_type: &DataType, to_type: 
&DataType) -> bool {
                 IntervalUnit::DayTime => true,
                 IntervalUnit::MonthDayNano => false, // Native type is i128
             }
+        },
+        (Int32, Interval(to_type)) => {
+            match to_type{
+                IntervalUnit::YearMonth => true,
+                IntervalUnit::DayTime => false,
+                IntervalUnit::MonthDayNano => false,
+            }
+        },
+        (Int64, Interval(to_type)) => {
+            match to_type{
+                IntervalUnit::YearMonth => false,
+                IntervalUnit::DayTime => true,
+                IntervalUnit::MonthDayNano => false,
+            }
         }
         (_, _) => false,
     }
@@ -1131,6 +1145,24 @@ pub fn cast_with_options(
                 from_type, to_type,
             ))),
         },
+        (Int32, Interval(to_type)) => match to_type {
+            IntervalUnit::YearMonth => {
+                cast_array_data::<IntervalYearMonthType>(array, 
Interval(to_type.clone()))
+            }
+            _ => Err(ArrowError::CastError(format!(
+                "Casting from {:?} to {:?} not supported",
+                from_type, to_type,
+            ))),
+        },
+        (Int64, Interval(to_type)) => match to_type {
+            IntervalUnit::DayTime => {
+                cast_array_data::<IntervalDayTimeType>(array, 
Interval(to_type.clone()))
+            }
+            _ => Err(ArrowError::CastError(format!(
+                "Casting from {:?} to {:?} not supported",
+                from_type, to_type,
+            ))),
+        },
         (_, _) => Err(ArrowError::CastError(format!(
             "Casting from {:?} to {:?} not supported",
             from_type, to_type,
diff --git a/integration-testing/src/lib.rs b/integration-testing/src/lib.rs
index e59cce2..3a6ee4c 100644
--- a/integration-testing/src/lib.rs
+++ b/integration-testing/src/lib.rs
@@ -202,6 +202,39 @@ fn array_from_json(
                         Value::String(s) => {
                             s.parse().expect("Unable to parse string as i64")
                         }
+                        Value::Object(ref map)
+                            if map.contains_key("days")
+                                && map.contains_key("milliseconds") =>
+                        {
+                            match field.data_type() {
+                                DataType::Interval(IntervalUnit::DayTime) => {
+                                    let days = map.get("days").unwrap();
+                                    let milliseconds = 
map.get("milliseconds").unwrap();
+
+                                    match (days, milliseconds) {
+                                        (Value::Number(d), Value::Number(m)) 
=> {
+                                            let mut bytes = [0_u8; 8];
+                                            let m = (m.as_i64().unwrap() as 
i32)
+                                                .to_le_bytes();
+                                            let d = (d.as_i64().unwrap() as 
i32)
+                                                .to_le_bytes();
+
+                                            let c = [d, m].concat();
+                                            
bytes.copy_from_slice(c.as_slice());
+                                            i64::from_le_bytes(bytes)
+                                        }
+                                        _ => panic!(
+                                            "Unable to parse {:?} as interval 
daytime",
+                                            value
+                                        ),
+                                    }
+                                }
+                                _ => panic!(
+                                    "Unable to parse {:?} as interval daytime",
+                                    value
+                                ),
+                            }
+                        }
                         _ => panic!("Unable to parse {:?} as number", value),
                     }),
                     _ => b.append_null(),

Reply via email to