@@ -27,18 +27,18 @@ use crate::array::*;
27
27
use crate :: buffer:: { buffer_unary_not, Buffer , MutableBuffer } ;
28
28
use crate :: compute:: util:: combine_option_bitmap;
29
29
use crate :: datatypes:: {
30
- ArrowNativeType , ArrowNumericType , DataType , Date32Type , Date64Type , Float32Type ,
31
- Float64Type , Int16Type , Int32Type , Int64Type , Int8Type , IntervalDayTimeType ,
32
- IntervalMonthDayNanoType , IntervalUnit , IntervalYearMonthType , Time32MillisecondType ,
33
- Time32SecondType , Time64MicrosecondType , Time64NanosecondType , TimeUnit ,
34
- TimestampMicrosecondType , TimestampMillisecondType , TimestampNanosecondType ,
35
- TimestampSecondType , UInt16Type , UInt32Type , UInt64Type , UInt8Type ,
30
+ native_op:: ArrowNativeTypeOp , ArrowNativeType , ArrowNumericType , DataType ,
31
+ Date32Type , Date64Type , Float32Type , Float64Type , Int16Type , Int32Type , Int64Type ,
32
+ Int8Type , IntervalDayTimeType , IntervalMonthDayNanoType , IntervalUnit ,
33
+ IntervalYearMonthType , Time32MillisecondType , Time32SecondType ,
34
+ Time64MicrosecondType , Time64NanosecondType , TimeUnit , TimestampMicrosecondType ,
35
+ TimestampMillisecondType , TimestampNanosecondType , TimestampSecondType , UInt16Type ,
36
+ UInt32Type , UInt64Type , UInt8Type ,
36
37
} ;
37
38
#[ allow( unused_imports) ]
38
39
use crate :: downcast_dictionary_array;
39
40
use crate :: error:: { ArrowError , Result } ;
40
41
use crate :: util:: bit_util;
41
- use num:: ToPrimitive ;
42
42
use regex:: Regex ;
43
43
use std:: collections:: HashMap ;
44
44
@@ -1336,7 +1336,7 @@ macro_rules! dyn_compare_utf8_scalar {
1336
1336
/// Please refer to `f32::total_cmp` and `f64::total_cmp`.
1337
1337
pub fn eq_dyn_scalar < T > ( left : & dyn Array , right : T ) -> Result < BooleanArray >
1338
1338
where
1339
- T : num :: ToPrimitive + std :: fmt :: Debug ,
1339
+ T : ArrowNativeTypeOp ,
1340
1340
{
1341
1341
match left. data_type ( ) {
1342
1342
DataType :: Dictionary ( key_type, _value_type) => {
@@ -3051,24 +3051,12 @@ where
3051
3051
pub fn eq_scalar < T > ( left : & PrimitiveArray < T > , right : T :: Native ) -> Result < BooleanArray >
3052
3052
where
3053
3053
T : ArrowNumericType ,
3054
- T :: Native : num :: ToPrimitive + std :: fmt :: Debug ,
3054
+ T :: Native : ArrowNativeTypeOp ,
3055
3055
{
3056
3056
#[ cfg( feature = "simd" ) ]
3057
3057
return simd_compare_op_scalar ( left, right, T :: eq, |a, b| a == b) ;
3058
3058
#[ cfg( not( feature = "simd" ) ) ]
3059
- match left. data_type ( ) {
3060
- DataType :: Float32 => {
3061
- let left = as_primitive_array :: < Float32Type > ( left) ;
3062
- let right = try_to_type ! ( right, to_f32) ?;
3063
- compare_op_scalar ( left, |a : f32 | a. total_cmp ( & right) . is_eq ( ) )
3064
- }
3065
- DataType :: Float64 => {
3066
- let left = as_primitive_array :: < Float64Type > ( left) ;
3067
- let right = try_to_type ! ( right, to_f64) ?;
3068
- compare_op_scalar ( left, |a : f64 | a. total_cmp ( & right) . is_eq ( ) )
3069
- }
3070
- _ => compare_op_scalar ( left, |a| a == right) ,
3071
- }
3059
+ return compare_op_scalar ( left, |a| a. is_eq ( right) ) ;
3072
3060
}
3073
3061
3074
3062
/// Applies an unary and infallible comparison function to a primitive array.
@@ -3099,24 +3087,12 @@ where
3099
3087
pub fn neq_scalar < T > ( left : & PrimitiveArray < T > , right : T :: Native ) -> Result < BooleanArray >
3100
3088
where
3101
3089
T : ArrowNumericType ,
3102
- T :: Native : num :: ToPrimitive + std :: fmt :: Debug ,
3090
+ T :: Native : ArrowNativeTypeOp ,
3103
3091
{
3104
3092
#[ cfg( feature = "simd" ) ]
3105
3093
return simd_compare_op_scalar ( left, right, T :: ne, |a, b| a != b) ;
3106
3094
#[ cfg( not( feature = "simd" ) ) ]
3107
- match left. data_type ( ) {
3108
- DataType :: Float32 => {
3109
- let left = as_primitive_array :: < Float32Type > ( left) ;
3110
- let right = try_to_type ! ( right, to_f32) ?;
3111
- compare_op_scalar ( left, |a : f32 | a. total_cmp ( & right) . is_ne ( ) )
3112
- }
3113
- DataType :: Float64 => {
3114
- let left = as_primitive_array :: < Float64Type > ( left) ;
3115
- let right = try_to_type ! ( right, to_f64) ?;
3116
- compare_op_scalar ( left, |a : f64 | a. total_cmp ( & right) . is_ne ( ) )
3117
- }
3118
- _ => compare_op_scalar ( left, |a| a != right) ,
3119
- }
3095
+ return compare_op_scalar ( left, |a| a. is_ne ( right) ) ;
3120
3096
}
3121
3097
3122
3098
/// Perform `left < right` operation on two [`PrimitiveArray`]s. Null values are less than non-null
@@ -3140,24 +3116,12 @@ where
3140
3116
pub fn lt_scalar < T > ( left : & PrimitiveArray < T > , right : T :: Native ) -> Result < BooleanArray >
3141
3117
where
3142
3118
T : ArrowNumericType ,
3143
- T :: Native : num :: ToPrimitive + std :: fmt :: Debug ,
3119
+ T :: Native : ArrowNativeTypeOp ,
3144
3120
{
3145
3121
#[ cfg( feature = "simd" ) ]
3146
3122
return simd_compare_op_scalar ( left, right, T :: lt, |a, b| a < b) ;
3147
3123
#[ cfg( not( feature = "simd" ) ) ]
3148
- match left. data_type ( ) {
3149
- DataType :: Float32 => {
3150
- let left = as_primitive_array :: < Float32Type > ( left) ;
3151
- let right = try_to_type ! ( right, to_f32) ?;
3152
- compare_op_scalar ( left, |a : f32 | a. total_cmp ( & right) . is_lt ( ) )
3153
- }
3154
- DataType :: Float64 => {
3155
- let left = as_primitive_array :: < Float64Type > ( left) ;
3156
- let right = try_to_type ! ( right, to_f64) ?;
3157
- compare_op_scalar ( left, |a : f64 | a. total_cmp ( & right) . is_lt ( ) )
3158
- }
3159
- _ => compare_op_scalar ( left, |a| a < right) ,
3160
- }
3124
+ return compare_op_scalar ( left, |a| a. is_lt ( right) ) ;
3161
3125
}
3162
3126
3163
3127
/// Perform `left <= right` operation on two [`PrimitiveArray`]s. Null values are less than non-null
@@ -3184,24 +3148,12 @@ where
3184
3148
pub fn lt_eq_scalar < T > ( left : & PrimitiveArray < T > , right : T :: Native ) -> Result < BooleanArray >
3185
3149
where
3186
3150
T : ArrowNumericType ,
3187
- T :: Native : num :: ToPrimitive + std :: fmt :: Debug ,
3151
+ T :: Native : ArrowNativeTypeOp ,
3188
3152
{
3189
3153
#[ cfg( feature = "simd" ) ]
3190
3154
return simd_compare_op_scalar ( left, right, T :: le, |a, b| a <= b) ;
3191
3155
#[ cfg( not( feature = "simd" ) ) ]
3192
- match left. data_type ( ) {
3193
- DataType :: Float32 => {
3194
- let left = as_primitive_array :: < Float32Type > ( left) ;
3195
- let right = try_to_type ! ( right, to_f32) ?;
3196
- compare_op_scalar ( left, |a : f32 | a. total_cmp ( & right) . is_le ( ) )
3197
- }
3198
- DataType :: Float64 => {
3199
- let left = as_primitive_array :: < Float64Type > ( left) ;
3200
- let right = try_to_type ! ( right, to_f64) ?;
3201
- compare_op_scalar ( left, |a : f64 | a. total_cmp ( & right) . is_le ( ) )
3202
- }
3203
- _ => compare_op_scalar ( left, |a| a <= right) ,
3204
- }
3156
+ return compare_op_scalar ( left, |a| a. is_le ( right) ) ;
3205
3157
}
3206
3158
3207
3159
/// Perform `left > right` operation on two [`PrimitiveArray`]s. Non-null values are greater than null
@@ -3225,24 +3177,12 @@ where
3225
3177
pub fn gt_scalar < T > ( left : & PrimitiveArray < T > , right : T :: Native ) -> Result < BooleanArray >
3226
3178
where
3227
3179
T : ArrowNumericType ,
3228
- T :: Native : num :: ToPrimitive + std :: fmt :: Debug ,
3180
+ T :: Native : ArrowNativeTypeOp ,
3229
3181
{
3230
3182
#[ cfg( feature = "simd" ) ]
3231
3183
return simd_compare_op_scalar ( left, right, T :: gt, |a, b| a > b) ;
3232
3184
#[ cfg( not( feature = "simd" ) ) ]
3233
- match left. data_type ( ) {
3234
- DataType :: Float32 => {
3235
- let left = as_primitive_array :: < Float32Type > ( left) ;
3236
- let right = try_to_type ! ( right, to_f32) ?;
3237
- compare_op_scalar ( left, |a : f32 | a. total_cmp ( & right) . is_gt ( ) )
3238
- }
3239
- DataType :: Float64 => {
3240
- let left = as_primitive_array :: < Float64Type > ( left) ;
3241
- let right = try_to_type ! ( right, to_f64) ?;
3242
- compare_op_scalar ( left, |a : f64 | a. total_cmp ( & right) . is_gt ( ) )
3243
- }
3244
- _ => compare_op_scalar ( left, |a| a > right) ,
3245
- }
3185
+ return compare_op_scalar ( left, |a| a. is_gt ( right) ) ;
3246
3186
}
3247
3187
3248
3188
/// Perform `left >= right` operation on two [`PrimitiveArray`]s. Non-null values are greater than null
@@ -3269,24 +3209,12 @@ where
3269
3209
pub fn gt_eq_scalar < T > ( left : & PrimitiveArray < T > , right : T :: Native ) -> Result < BooleanArray >
3270
3210
where
3271
3211
T : ArrowNumericType ,
3272
- T :: Native : num :: ToPrimitive + std :: fmt :: Debug ,
3212
+ T :: Native : ArrowNativeTypeOp ,
3273
3213
{
3274
3214
#[ cfg( feature = "simd" ) ]
3275
3215
return simd_compare_op_scalar ( left, right, T :: ge, |a, b| a >= b) ;
3276
3216
#[ cfg( not( feature = "simd" ) ) ]
3277
- match left. data_type ( ) {
3278
- DataType :: Float32 => {
3279
- let left = as_primitive_array :: < Float32Type > ( left) ;
3280
- let right = try_to_type ! ( right, to_f32) ?;
3281
- compare_op_scalar ( left, |a : f32 | a. total_cmp ( & right) . is_ge ( ) )
3282
- }
3283
- DataType :: Float64 => {
3284
- let left = as_primitive_array :: < Float64Type > ( left) ;
3285
- let right = try_to_type ! ( right, to_f64) ?;
3286
- compare_op_scalar ( left, |a : f64 | a. total_cmp ( & right) . is_ge ( ) )
3287
- }
3288
- _ => compare_op_scalar ( left, |a| a >= right) ,
3289
- }
3217
+ return compare_op_scalar ( left, |a| a. is_ge ( right) ) ;
3290
3218
}
3291
3219
3292
3220
/// Checks if a [`GenericListArray`] contains a value in the [`PrimitiveArray`]
0 commit comments