alamb commented on a change in pull request #1196:
URL: https://github.com/apache/arrow-rs/pull/1196#discussion_r787180645



##########
File path: arrow/src/compute/kernels/cast.rs
##########
@@ -221,6 +221,14 @@ pub fn can_cast_types(from_type: &DataType, to_type: 
&DataType) -> bool {
         (Timestamp(_, _), Timestamp(_, _) | Date32 | Date64) => true,
         // date64 to timestamp might not make sense,
         (Int64, Duration(_)) => true,
+        (Duration(_), Int64) => true,
+        (Interval(from_type), Int64) => {
+            match from_type{
+                IntervalUnit::YearMonth => true,
+                IntervalUnit::DayTime => true,
+                IntervalUnit::MonthDayNano => false, // Native type is i128

Review comment:
       One possible way to support this would be to cast to `Decimal` which can 
represent the full type
   
   Though that is not very ideal for various reasons either. 
   
   So for now, this looks good 👍 

##########
File path: arrow/src/compute/kernels/cast.rs
##########
@@ -1111,6 +1118,17 @@ pub fn cast_with_options(
                 }
             }
         }
+        (Duration(_), Int64) => cast_array_data::<Int64Type>(array, 
to_type.clone()),
+        (Interval(from_type), Int64) => match from_type {
+            IntervalUnit::YearMonth => {
+                cast_numeric_arrays::<IntervalYearMonthType, Int64Type>(array)
+            }
+            IntervalUnit::DayTime => cast_array_data::<Int64Type>(array, 
to_type.clone()),

Review comment:
       I guess this makes sense (to pass back the underlying data). The DayTime 
value is actually made up of two fields (days / milliseconds): 
https://github.com/apache/arrow/blob/master/format/Schema.fbs#L361-L365
   
   I wonder if using one of the temporal kernels might make more sense for your 
usecase: https://docs.rs/arrow/7.0.0/arrow/compute/kernels/temporal/index.html#
   
   




-- 
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]


Reply via email to