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

tustvold 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 16f4a7f9701 fix: https://github.com/apache/arrow-rs/issues/5599 (#5603)
16f4a7f9701 is described below

commit 16f4a7f9701ac5d8f96a1fc45d30f632ab0816d3
Author: Jovansonlee Cesar <[email protected]>
AuthorDate: Tue Apr 9 17:44:18 2024 +0800

    fix: https://github.com/apache/arrow-rs/issues/5599 (#5603)
---
 arrow-array/src/array/primitive_array.rs |  6 +++---
 arrow-buffer/src/native.rs               | 20 ++++++++++++++++++++
 2 files changed, 23 insertions(+), 3 deletions(-)

diff --git a/arrow-array/src/array/primitive_array.rs 
b/arrow-array/src/array/primitive_array.rs
index ddae770d383..924cab1ac83 100644
--- a/arrow-array/src/array/primitive_array.rs
+++ b/arrow-array/src/array/primitive_array.rs
@@ -1097,7 +1097,7 @@ impl<T: ArrowPrimitiveType> std::fmt::Debug for 
PrimitiveArray<T> {
         write!(f, "PrimitiveArray<{data_type:?}>\n[\n")?;
         print_long_array(self, f, |array, index, f| match data_type {
             DataType::Date32 | DataType::Date64 => {
-                let v = self.value(index).to_isize().unwrap() as i64;
+                let v = self.value(index).to_i64().unwrap();
                 match as_date::<T>(v) {
                     Some(date) => write!(f, "{date:?}"),
                     None => {
@@ -1109,7 +1109,7 @@ impl<T: ArrowPrimitiveType> std::fmt::Debug for 
PrimitiveArray<T> {
                 }
             }
             DataType::Time32(_) | DataType::Time64(_) => {
-                let v = self.value(index).to_isize().unwrap() as i64;
+                let v = self.value(index).to_i64().unwrap();
                 match as_time::<T>(v) {
                     Some(time) => write!(f, "{time:?}"),
                     None => {
@@ -1121,7 +1121,7 @@ impl<T: ArrowPrimitiveType> std::fmt::Debug for 
PrimitiveArray<T> {
                 }
             }
             DataType::Timestamp(_, tz_string_opt) => {
-                let v = self.value(index).to_isize().unwrap() as i64;
+                let v = self.value(index).to_i64().unwrap();
                 match tz_string_opt {
                     // for Timestamp with TimeZone
                     Some(tz_string) => {
diff --git a/arrow-buffer/src/native.rs b/arrow-buffer/src/native.rs
index 5184d60ac1f..680974351a4 100644
--- a/arrow-buffer/src/native.rs
+++ b/arrow-buffer/src/native.rs
@@ -75,6 +75,12 @@ pub trait ArrowNativeType:
     /// in truncation/overflow
     fn to_isize(self) -> Option<isize>;
 
+    /// Convert native type to i64.
+    ///
+    /// Returns `None` if [`Self`] is not an integer or conversion would result
+    /// in truncation/overflow
+    fn to_i64(self) -> Option<i64>;
+
     /// Convert native type from i32.
     ///
     /// Returns `None` if [`Self`] is not `i32`
@@ -119,6 +125,11 @@ macro_rules! native_integer {
                 self.try_into().ok()
             }
 
+            #[inline]
+            fn to_i64(self) -> Option<i64> {
+                self.try_into().ok()
+            }
+
             #[inline]
             fn as_usize(self) -> usize {
                 self as _
@@ -170,6 +181,11 @@ macro_rules! native_float {
                 None
             }
 
+            #[inline]
+            fn to_i64(self) -> Option<i64> {
+                None
+            }
+
             #[inline]
             fn as_usize($s) -> usize {
                 $as_usize
@@ -212,6 +228,10 @@ impl ArrowNativeType for i256 {
     fn to_isize(self) -> Option<isize> {
         self.to_i128()?.try_into().ok()
     }
+
+    fn to_i64(self) -> Option<i64> {
+        self.to_i128()?.try_into().ok()
+    }
 }
 
 /// Allows conversion from supported Arrow types to a byte slice.

Reply via email to