viirya commented on code in PR #5040:
URL: https://github.com/apache/arrow-rs/pull/5040#discussion_r1384119989


##########
arrow-cast/src/cast.rs:
##########
@@ -1621,24 +1621,104 @@ pub fn cast_with_options(
                 .unary::<_, Time64MicrosecondType>(|x| x / (NANOSECONDS / 
MICROSECONDS)),
         )),
 
-        (Timestamp(TimeUnit::Second, _), Int64) => {
-            cast_reinterpret_arrays::<TimestampSecondType, Int64Type>(array)
+        (Timestamp(TimeUnit::Second, _), _) if to_type.is_integer() => {
+            let array = cast_reinterpret_arrays::<TimestampSecondType, 
Int64Type>(array)?;
+
+            match to_type {
+                Int8 => cast_numeric_arrays::<Int64Type, Int8Type>(&array, 
cast_options),
+                Int16 => cast_numeric_arrays::<Int64Type, Int16Type>(&array, 
cast_options),
+                Int32 => cast_numeric_arrays::<Int64Type, Int32Type>(&array, 
cast_options),
+                Int64 => Ok(array),
+                UInt8 => cast_numeric_arrays::<Int64Type, UInt8Type>(&array, 
cast_options),
+                UInt16 => cast_numeric_arrays::<Int64Type, UInt16Type>(&array, 
cast_options),
+                UInt32 => cast_numeric_arrays::<Int64Type, UInt32Type>(&array, 
cast_options),
+                UInt64 => cast_numeric_arrays::<Int64Type, UInt64Type>(&array, 
cast_options),
+                _ => Err(ArrowError::CastError(format!(
+                    "Casting from {:?} to {:?} not supported",
+                    from_type, to_type
+                ))),
+            }
         }
-        (Timestamp(TimeUnit::Millisecond, _), Int64) => {
-            cast_reinterpret_arrays::<TimestampMillisecondType, 
Int64Type>(array)
+        (Timestamp(TimeUnit::Millisecond, _), _) if to_type.is_integer() => {
+            let array = cast_reinterpret_arrays::<TimestampMillisecondType, 
Int64Type>(array)?;
+
+            match to_type {
+                Int8 => cast_numeric_arrays::<Int64Type, Int8Type>(&array, 
cast_options),
+                Int16 => cast_numeric_arrays::<Int64Type, Int16Type>(&array, 
cast_options),
+                Int32 => cast_numeric_arrays::<Int64Type, Int32Type>(&array, 
cast_options),
+                Int64 => Ok(array),
+                UInt8 => cast_numeric_arrays::<Int64Type, UInt8Type>(&array, 
cast_options),
+                UInt16 => cast_numeric_arrays::<Int64Type, UInt16Type>(&array, 
cast_options),
+                UInt32 => cast_numeric_arrays::<Int64Type, UInt32Type>(&array, 
cast_options),
+                UInt64 => cast_numeric_arrays::<Int64Type, UInt64Type>(&array, 
cast_options),
+                _ => Err(ArrowError::CastError(format!(
+                    "Casting from {:?} to {:?} not supported",
+                    from_type, to_type
+                ))),
+            }
         }
-        (Timestamp(TimeUnit::Microsecond, _), Int64) => {
-            cast_reinterpret_arrays::<TimestampMicrosecondType, 
Int64Type>(array)
+        (Timestamp(TimeUnit::Microsecond, _), _) if to_type.is_integer() => {
+            let array = cast_reinterpret_arrays::<TimestampMicrosecondType, 
Int64Type>(array)?;
+
+            match to_type {

Review Comment:
   Yea, it's simpler. 👍 



##########
arrow-cast/src/cast.rs:
##########
@@ -1621,24 +1621,104 @@ pub fn cast_with_options(
                 .unary::<_, Time64MicrosecondType>(|x| x / (NANOSECONDS / 
MICROSECONDS)),
         )),
 
-        (Timestamp(TimeUnit::Second, _), Int64) => {
-            cast_reinterpret_arrays::<TimestampSecondType, Int64Type>(array)
+        (Timestamp(TimeUnit::Second, _), _) if to_type.is_integer() => {
+            let array = cast_reinterpret_arrays::<TimestampSecondType, 
Int64Type>(array)?;
+
+            match to_type {
+                Int8 => cast_numeric_arrays::<Int64Type, Int8Type>(&array, 
cast_options),
+                Int16 => cast_numeric_arrays::<Int64Type, Int16Type>(&array, 
cast_options),
+                Int32 => cast_numeric_arrays::<Int64Type, Int32Type>(&array, 
cast_options),
+                Int64 => Ok(array),
+                UInt8 => cast_numeric_arrays::<Int64Type, UInt8Type>(&array, 
cast_options),
+                UInt16 => cast_numeric_arrays::<Int64Type, UInt16Type>(&array, 
cast_options),
+                UInt32 => cast_numeric_arrays::<Int64Type, UInt32Type>(&array, 
cast_options),
+                UInt64 => cast_numeric_arrays::<Int64Type, UInt64Type>(&array, 
cast_options),
+                _ => Err(ArrowError::CastError(format!(
+                    "Casting from {:?} to {:?} not supported",
+                    from_type, to_type
+                ))),
+            }
         }
-        (Timestamp(TimeUnit::Millisecond, _), Int64) => {
-            cast_reinterpret_arrays::<TimestampMillisecondType, 
Int64Type>(array)
+        (Timestamp(TimeUnit::Millisecond, _), _) if to_type.is_integer() => {
+            let array = cast_reinterpret_arrays::<TimestampMillisecondType, 
Int64Type>(array)?;
+
+            match to_type {
+                Int8 => cast_numeric_arrays::<Int64Type, Int8Type>(&array, 
cast_options),
+                Int16 => cast_numeric_arrays::<Int64Type, Int16Type>(&array, 
cast_options),
+                Int32 => cast_numeric_arrays::<Int64Type, Int32Type>(&array, 
cast_options),
+                Int64 => Ok(array),
+                UInt8 => cast_numeric_arrays::<Int64Type, UInt8Type>(&array, 
cast_options),
+                UInt16 => cast_numeric_arrays::<Int64Type, UInt16Type>(&array, 
cast_options),
+                UInt32 => cast_numeric_arrays::<Int64Type, UInt32Type>(&array, 
cast_options),
+                UInt64 => cast_numeric_arrays::<Int64Type, UInt64Type>(&array, 
cast_options),
+                _ => Err(ArrowError::CastError(format!(
+                    "Casting from {:?} to {:?} not supported",
+                    from_type, to_type
+                ))),
+            }
         }
-        (Timestamp(TimeUnit::Microsecond, _), Int64) => {
-            cast_reinterpret_arrays::<TimestampMicrosecondType, 
Int64Type>(array)
+        (Timestamp(TimeUnit::Microsecond, _), _) if to_type.is_integer() => {
+            let array = cast_reinterpret_arrays::<TimestampMicrosecondType, 
Int64Type>(array)?;
+
+            match to_type {

Review Comment:
   Yea, it's simpler. 👍 



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