You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@arrow.apache.org by tu...@apache.org on 2022/11/04 21:32:37 UTC

[arrow-rs] branch master updated: Move ArrowNativeTypeOp to arrow-array (#2594) (#3018)

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 29b3fef8a Move ArrowNativeTypeOp to arrow-array (#2594) (#3018)
29b3fef8a is described below

commit 29b3fef8ac9b3aa6da4372fd92bd1d230e285720
Author: Raphael Taylor-Davies <17...@users.noreply.github.com>
AuthorDate: Sat Nov 5 10:32:31 2022 +1300

    Move ArrowNativeTypeOp to arrow-array (#2594) (#3018)
    
    * Move ArrowNativeTypeOp to arrow-array (#2594)
    
    * Fix features
---
 arrow-array/Cargo.toml                             |  2 +-
 .../native.rs => arrow-array/src/arithmetic.rs     | 47 +++++++++++-----------
 arrow-array/src/lib.rs                             |  3 ++
 arrow/src/datatypes/mod.rs                         |  4 +-
 4 files changed, 29 insertions(+), 27 deletions(-)

diff --git a/arrow-array/Cargo.toml b/arrow-array/Cargo.toml
index 21f66c87e..186e88ff1 100644
--- a/arrow-array/Cargo.toml
+++ b/arrow-array/Cargo.toml
@@ -51,7 +51,7 @@ arrow-data = { version = "26.0.0", path = "../arrow-data" }
 chrono = { version = "0.4", default-features = false, features = ["clock"] }
 chrono-tz = { version = "0.8", optional = true }
 num = { version = "0.4", default-features = false, features = ["std"] }
-half = { version = "2.1", default-features = false }
+half = { version = "2.1", default-features = false, features = ["num-traits"] }
 hashbrown = { version = "0.12", default-features = false }
 
 [dev-dependencies]
diff --git a/arrow/src/datatypes/native.rs b/arrow-array/src/arithmetic.rs
similarity index 85%
rename from arrow/src/datatypes/native.rs
rename to arrow-array/src/arithmetic.rs
index 28ef877a2..e596c0064 100644
--- a/arrow/src/datatypes/native.rs
+++ b/arrow-array/src/arithmetic.rs
@@ -15,9 +15,8 @@
 // specific language governing permissions and limitations
 // under the License.
 
-use crate::error::{ArrowError, Result};
-pub use arrow_array::ArrowPrimitiveType;
-pub use arrow_buffer::{i256, ArrowNativeType, ToByteSlice};
+use arrow_buffer::{i256, ArrowNativeType};
+use arrow_schema::ArrowError;
 use half::f16;
 use num::complex::ComplexFloat;
 
@@ -45,31 +44,31 @@ pub trait ArrowNativeTypeOp: ArrowNativeType {
     /// The multiplicative identity
     const ONE: Self;
 
-    fn add_checked(self, rhs: Self) -> Result<Self>;
+    fn add_checked(self, rhs: Self) -> Result<Self, ArrowError>;
 
     fn add_wrapping(self, rhs: Self) -> Self;
 
-    fn sub_checked(self, rhs: Self) -> Result<Self>;
+    fn sub_checked(self, rhs: Self) -> Result<Self, ArrowError>;
 
     fn sub_wrapping(self, rhs: Self) -> Self;
 
-    fn mul_checked(self, rhs: Self) -> Result<Self>;
+    fn mul_checked(self, rhs: Self) -> Result<Self, ArrowError>;
 
     fn mul_wrapping(self, rhs: Self) -> Self;
 
-    fn div_checked(self, rhs: Self) -> Result<Self>;
+    fn div_checked(self, rhs: Self) -> Result<Self, ArrowError>;
 
     fn div_wrapping(self, rhs: Self) -> Self;
 
-    fn mod_checked(self, rhs: Self) -> Result<Self>;
+    fn mod_checked(self, rhs: Self) -> Result<Self, ArrowError>;
 
     fn mod_wrapping(self, rhs: Self) -> Self;
 
-    fn neg_checked(self) -> Result<Self>;
+    fn neg_checked(self) -> Result<Self, ArrowError>;
 
     fn neg_wrapping(self) -> Self;
 
-    fn pow_checked(self, exp: u32) -> Result<Self>;
+    fn pow_checked(self, exp: u32) -> Result<Self, ArrowError>;
 
     fn pow_wrapping(self, exp: u32) -> Self;
 
@@ -97,7 +96,7 @@ macro_rules! native_type_op {
             const ZERO: Self = $zero;
             const ONE: Self = $one;
 
-            fn add_checked(self, rhs: Self) -> Result<Self> {
+            fn add_checked(self, rhs: Self) -> Result<Self, ArrowError> {
                 self.checked_add(rhs).ok_or_else(|| {
                     ArrowError::ComputeError(format!(
                         "Overflow happened on: {:?} + {:?}",
@@ -110,7 +109,7 @@ macro_rules! native_type_op {
                 self.wrapping_add(rhs)
             }
 
-            fn sub_checked(self, rhs: Self) -> Result<Self> {
+            fn sub_checked(self, rhs: Self) -> Result<Self, ArrowError> {
                 self.checked_sub(rhs).ok_or_else(|| {
                     ArrowError::ComputeError(format!(
                         "Overflow happened on: {:?} - {:?}",
@@ -123,7 +122,7 @@ macro_rules! native_type_op {
                 self.wrapping_sub(rhs)
             }
 
-            fn mul_checked(self, rhs: Self) -> Result<Self> {
+            fn mul_checked(self, rhs: Self) -> Result<Self, ArrowError> {
                 self.checked_mul(rhs).ok_or_else(|| {
                     ArrowError::ComputeError(format!(
                         "Overflow happened on: {:?} * {:?}",
@@ -136,7 +135,7 @@ macro_rules! native_type_op {
                 self.wrapping_mul(rhs)
             }
 
-            fn div_checked(self, rhs: Self) -> Result<Self> {
+            fn div_checked(self, rhs: Self) -> Result<Self, ArrowError> {
                 if rhs.is_zero() {
                     Err(ArrowError::DivideByZero)
                 } else {
@@ -153,7 +152,7 @@ macro_rules! native_type_op {
                 self.wrapping_div(rhs)
             }
 
-            fn mod_checked(self, rhs: Self) -> Result<Self> {
+            fn mod_checked(self, rhs: Self) -> Result<Self, ArrowError> {
                 if rhs.is_zero() {
                     Err(ArrowError::DivideByZero)
                 } else {
@@ -170,13 +169,13 @@ macro_rules! native_type_op {
                 self.wrapping_rem(rhs)
             }
 
-            fn neg_checked(self) -> Result<Self> {
+            fn neg_checked(self) -> Result<Self, ArrowError> {
                 self.checked_neg().ok_or_else(|| {
                     ArrowError::ComputeError(format!("Overflow happened on: {:?}", self))
                 })
             }
 
-            fn pow_checked(self, exp: u32) -> Result<Self> {
+            fn pow_checked(self, exp: u32) -> Result<Self, ArrowError> {
                 self.checked_pow(exp).ok_or_else(|| {
                     ArrowError::ComputeError(format!("Overflow happened on: {:?}", self))
                 })
@@ -238,7 +237,7 @@ macro_rules! native_type_float_op {
             const ZERO: Self = $zero;
             const ONE: Self = $one;
 
-            fn add_checked(self, rhs: Self) -> Result<Self> {
+            fn add_checked(self, rhs: Self) -> Result<Self, ArrowError> {
                 Ok(self + rhs)
             }
 
@@ -246,7 +245,7 @@ macro_rules! native_type_float_op {
                 self + rhs
             }
 
-            fn sub_checked(self, rhs: Self) -> Result<Self> {
+            fn sub_checked(self, rhs: Self) -> Result<Self, ArrowError> {
                 Ok(self - rhs)
             }
 
@@ -254,7 +253,7 @@ macro_rules! native_type_float_op {
                 self - rhs
             }
 
-            fn mul_checked(self, rhs: Self) -> Result<Self> {
+            fn mul_checked(self, rhs: Self) -> Result<Self, ArrowError> {
                 Ok(self * rhs)
             }
 
@@ -262,7 +261,7 @@ macro_rules! native_type_float_op {
                 self * rhs
             }
 
-            fn div_checked(self, rhs: Self) -> Result<Self> {
+            fn div_checked(self, rhs: Self) -> Result<Self, ArrowError> {
                 if rhs.is_zero() {
                     Err(ArrowError::DivideByZero)
                 } else {
@@ -274,7 +273,7 @@ macro_rules! native_type_float_op {
                 self / rhs
             }
 
-            fn mod_checked(self, rhs: Self) -> Result<Self> {
+            fn mod_checked(self, rhs: Self) -> Result<Self, ArrowError> {
                 if rhs.is_zero() {
                     Err(ArrowError::DivideByZero)
                 } else {
@@ -286,7 +285,7 @@ macro_rules! native_type_float_op {
                 self % rhs
             }
 
-            fn neg_checked(self) -> Result<Self> {
+            fn neg_checked(self) -> Result<Self, ArrowError> {
                 Ok(-self)
             }
 
@@ -294,7 +293,7 @@ macro_rules! native_type_float_op {
                 -self
             }
 
-            fn pow_checked(self, exp: u32) -> Result<Self> {
+            fn pow_checked(self, exp: u32) -> Result<Self, ArrowError> {
                 Ok(self.powi(exp as i32))
             }
 
diff --git a/arrow-array/src/lib.rs b/arrow-array/src/lib.rs
index e616099cc..5c86978dc 100644
--- a/arrow-array/src/lib.rs
+++ b/arrow-array/src/lib.rs
@@ -164,6 +164,9 @@ pub use array::*;
 mod record_batch;
 pub use record_batch::{RecordBatch, RecordBatchOptions};
 
+mod arithmetic;
+pub use arithmetic::ArrowNativeTypeOp;
+
 pub mod builder;
 pub mod cast;
 mod delta;
diff --git a/arrow/src/datatypes/mod.rs b/arrow/src/datatypes/mod.rs
index 01462aeca..5d625a051 100644
--- a/arrow/src/datatypes/mod.rs
+++ b/arrow/src/datatypes/mod.rs
@@ -22,12 +22,12 @@
 //!  * [`Field`](crate::datatypes::Field) to describe one field within a schema.
 //!  * [`DataType`](crate::datatypes::DataType) to describe the type of a field.
 
-mod native;
-pub use native::*;
 mod numeric;
 pub use numeric::*;
 
 pub use arrow_array::types::*;
+pub use arrow_array::{ArrowNativeTypeOp, ArrowPrimitiveType};
+pub use arrow_buffer::{i256, ArrowNativeType, ToByteSlice};
 pub use arrow_data::decimal::*;
 pub use arrow_schema::{
     DataType, Field, IntervalUnit, Schema, SchemaRef, TimeUnit, UnionMode,