@@ -27,18 +27,17 @@ use std::ops::{Div, Neg, Rem};
27
27
use num:: { One , Zero } ;
28
28
29
29
use crate :: array:: * ;
30
- use crate :: buffer:: Buffer ;
31
30
#[ cfg( feature = "simd" ) ]
32
31
use crate :: buffer:: MutableBuffer ;
33
32
use crate :: compute:: kernels:: arity:: unary;
34
- use crate :: compute:: util:: combine_option_bitmap;
35
33
use crate :: compute:: {
36
34
binary, binary_opt, try_binary, try_unary, try_unary_dyn, unary_dyn,
37
35
} ;
38
36
use crate :: datatypes:: {
39
37
native_op:: ArrowNativeTypeOp , ArrowNumericType , DataType , Date32Type , Date64Type ,
40
38
IntervalDayTimeType , IntervalMonthDayNanoType , IntervalUnit , IntervalYearMonthType ,
41
39
} ;
40
+ #[ cfg( feature = "dyn_arith_dict" ) ]
42
41
use crate :: datatypes:: {
43
42
Float32Type , Float64Type , Int16Type , Int32Type , Int64Type , Int8Type , UInt16Type ,
44
43
UInt32Type , UInt64Type , UInt8Type ,
@@ -122,12 +121,13 @@ where
122
121
/// This function errors if:
123
122
/// * the arrays have different lengths
124
123
/// * there is an element where both left and right values are valid and the right value is `0`
124
+ #[ cfg( feature = "dyn_arith_dict" ) ]
125
125
fn math_checked_divide_op_on_iters < T , F > (
126
126
left : impl Iterator < Item = Option < T :: Native > > ,
127
127
right : impl Iterator < Item = Option < T :: Native > > ,
128
128
op : F ,
129
129
len : usize ,
130
- null_bit_buffer : Option < Buffer > ,
130
+ null_bit_buffer : Option < crate :: buffer :: Buffer > ,
131
131
) -> Result < PrimitiveArray < T > >
132
132
where
133
133
T : ArrowNumericType ,
@@ -143,15 +143,15 @@ where
143
143
}
144
144
} ) ;
145
145
// Safety: Iterator comes from a PrimitiveArray which reports its size correctly
146
- unsafe { Buffer :: try_from_trusted_len_iter ( values) }
146
+ unsafe { crate :: buffer :: Buffer :: try_from_trusted_len_iter ( values) }
147
147
} else {
148
148
// no value is null
149
149
let values = left
150
150
. map ( |l| l. unwrap ( ) )
151
151
. zip ( right. map ( |r| r. unwrap ( ) ) )
152
152
. map ( |( left, right) | op ( left, right) ) ;
153
153
// Safety: Iterator comes from a PrimitiveArray which reports its size correctly
154
- unsafe { Buffer :: try_from_trusted_len_iter ( values) }
154
+ unsafe { crate :: buffer :: Buffer :: try_from_trusted_len_iter ( values) }
155
155
} ?;
156
156
157
157
let data = unsafe {
@@ -316,8 +316,10 @@ where
316
316
}
317
317
318
318
// Create the combined `Bitmap`
319
- let null_bit_buffer =
320
- combine_option_bitmap ( & [ left. data_ref ( ) , right. data_ref ( ) ] , left. len ( ) ) ?;
319
+ let null_bit_buffer = crate :: compute:: util:: combine_option_bitmap (
320
+ & [ left. data_ref ( ) , right. data_ref ( ) ] ,
321
+ left. len ( ) ,
322
+ ) ?;
321
323
322
324
let lanes = T :: lanes ( ) ;
323
325
let buffer_size = left. len ( ) * std:: mem:: size_of :: < T :: Native > ( ) ;
@@ -425,6 +427,7 @@ where
425
427
}
426
428
427
429
/// Applies $OP to $LEFT and $RIGHT which are two dictionaries which have (the same) key type $KT
430
+ #[ cfg( feature = "dyn_arith_dict" ) ]
428
431
macro_rules! typed_dict_op {
429
432
( $LEFT: expr, $RIGHT: expr, $OP: expr, $KT: tt, $MATH_OP: ident) => { {
430
433
match ( $LEFT. value_type( ) , $RIGHT. value_type( ) ) {
@@ -476,6 +479,7 @@ macro_rules! typed_dict_op {
476
479
} } ;
477
480
}
478
481
482
+ #[ cfg( feature = "dyn_arith_dict" ) ]
479
483
macro_rules! typed_dict_math_op {
480
484
// Applies `LEFT OP RIGHT` when `LEFT` and `RIGHT` both are `DictionaryArray`
481
485
( $LEFT: expr, $RIGHT: expr, $OP: expr, $MATH_OP: ident) => { {
@@ -536,8 +540,20 @@ macro_rules! typed_dict_math_op {
536
540
} } ;
537
541
}
538
542
543
+ #[ cfg( not( feature = "dyn_arith_dict" ) ) ]
544
+ macro_rules! typed_dict_math_op {
545
+ // Applies `LEFT OP RIGHT` when `LEFT` and `RIGHT` both are `DictionaryArray`
546
+ ( $LEFT: expr, $RIGHT: expr, $OP: expr, $MATH_OP: ident) => { {
547
+ Err ( ArrowError :: CastError ( format!(
548
+ "Arithmetic on arrays of type {} with array of type {} requires \" dyn_arith_dict\" feature" ,
549
+ $LEFT. data_type( ) , $RIGHT. data_type( )
550
+ ) ) )
551
+ } } ;
552
+ }
553
+
539
554
/// Perform given operation on two `DictionaryArray`s.
540
555
/// Returns an error if the two arrays have different value type
556
+ #[ cfg( feature = "dyn_arith_dict" ) ]
541
557
fn math_op_dict < K , T , F > (
542
558
left : & DictionaryArray < K > ,
543
559
right : & DictionaryArray < K > ,
@@ -593,6 +609,7 @@ where
593
609
594
610
/// Perform given operation on two `DictionaryArray`s.
595
611
/// Returns an error if the two arrays have different value type
612
+ #[ cfg( feature = "dyn_arith_dict" ) ]
596
613
fn math_checked_op_dict < K , T , F > (
597
614
left : & DictionaryArray < K > ,
598
615
right : & DictionaryArray < K > ,
@@ -626,6 +643,7 @@ where
626
643
/// This function errors if:
627
644
/// * the arrays have different lengths
628
645
/// * there is an element where both left and right values are valid and the right value is `0`
646
+ #[ cfg( feature = "dyn_arith_dict" ) ]
629
647
fn math_divide_checked_op_dict < K , T , F > (
630
648
left : & DictionaryArray < K > ,
631
649
right : & DictionaryArray < K > ,
@@ -645,8 +663,10 @@ where
645
663
) ) ) ;
646
664
}
647
665
648
- let null_bit_buffer =
649
- combine_option_bitmap ( & [ left. data_ref ( ) , right. data_ref ( ) ] , left. len ( ) ) ?;
666
+ let null_bit_buffer = crate :: compute:: util:: combine_option_bitmap (
667
+ & [ left. data_ref ( ) , right. data_ref ( ) ] ,
668
+ left. len ( ) ,
669
+ ) ?;
650
670
651
671
// Safety justification: Since the inputs are valid Arrow arrays, all values are
652
672
// valid indexes into the dictionary (which is verified during construction)
@@ -1484,7 +1504,7 @@ where
1484
1504
mod tests {
1485
1505
use super :: * ;
1486
1506
use crate :: array:: Int32Array ;
1487
- use crate :: datatypes:: Date64Type ;
1507
+ use crate :: datatypes:: { Date64Type , Int32Type , Int8Type } ;
1488
1508
use chrono:: NaiveDate ;
1489
1509
1490
1510
#[ test]
@@ -1605,6 +1625,7 @@ mod tests {
1605
1625
}
1606
1626
1607
1627
#[ test]
1628
+ #[ cfg( feature = "dyn_arith_dict" ) ]
1608
1629
fn test_primitive_array_add_dyn_dict ( ) {
1609
1630
let mut builder = PrimitiveDictionaryBuilder :: < Int8Type , Int32Type > :: new ( ) ;
1610
1631
builder. append ( 5 ) . unwrap ( ) ;
@@ -1683,6 +1704,7 @@ mod tests {
1683
1704
}
1684
1705
1685
1706
#[ test]
1707
+ #[ cfg( feature = "dyn_arith_dict" ) ]
1686
1708
fn test_primitive_array_subtract_dyn_dict ( ) {
1687
1709
let mut builder = PrimitiveDictionaryBuilder :: < Int8Type , Int32Type > :: new ( ) ;
1688
1710
builder. append ( 15 ) . unwrap ( ) ;
@@ -1761,6 +1783,7 @@ mod tests {
1761
1783
}
1762
1784
1763
1785
#[ test]
1786
+ #[ cfg( feature = "dyn_arith_dict" ) ]
1764
1787
fn test_primitive_array_multiply_dyn_dict ( ) {
1765
1788
let mut builder = PrimitiveDictionaryBuilder :: < Int8Type , Int32Type > :: new ( ) ;
1766
1789
builder. append ( 5 ) . unwrap ( ) ;
@@ -1801,6 +1824,7 @@ mod tests {
1801
1824
}
1802
1825
1803
1826
#[ test]
1827
+ #[ cfg( feature = "dyn_arith_dict" ) ]
1804
1828
fn test_primitive_array_divide_dyn_dict ( ) {
1805
1829
let mut builder = PrimitiveDictionaryBuilder :: < Int8Type , Int32Type > :: new ( ) ;
1806
1830
builder. append ( 15 ) . unwrap ( ) ;
@@ -2322,6 +2346,7 @@ mod tests {
2322
2346
2323
2347
#[ test]
2324
2348
#[ should_panic( expected = "DivideByZero" ) ]
2349
+ #[ cfg( feature = "dyn_arith_dict" ) ]
2325
2350
fn test_int_array_divide_dyn_by_zero_dict ( ) {
2326
2351
let mut builder =
2327
2352
PrimitiveDictionaryBuilder :: < Int8Type , Int32Type > :: with_capacity ( 1 , 1 ) ;
@@ -2338,7 +2363,9 @@ mod tests {
2338
2363
2339
2364
#[ test]
2340
2365
#[ should_panic( expected = "DivideByZero" ) ]
2366
+ #[ cfg( feature = "dyn_arith_dict" ) ]
2341
2367
fn test_f32_dict_array_divide_dyn_by_zero ( ) {
2368
+ use crate :: datatypes:: Float32Type ;
2342
2369
let mut builder =
2343
2370
PrimitiveDictionaryBuilder :: < Int8Type , Float32Type > :: with_capacity ( 1 , 1 ) ;
2344
2371
builder. append ( 1.5 ) . unwrap ( ) ;
@@ -2601,6 +2628,7 @@ mod tests {
2601
2628
}
2602
2629
2603
2630
#[ test]
2631
+ #[ cfg( feature = "dyn_arith_dict" ) ]
2604
2632
fn test_dictionary_add_dyn_wrapping_overflow ( ) {
2605
2633
let mut builder =
2606
2634
PrimitiveDictionaryBuilder :: < Int8Type , Int32Type > :: with_capacity ( 2 , 2 ) ;
@@ -2637,6 +2665,7 @@ mod tests {
2637
2665
}
2638
2666
2639
2667
#[ test]
2668
+ #[ cfg( feature = "dyn_arith_dict" ) ]
2640
2669
fn test_dictionary_subtract_dyn_wrapping_overflow ( ) {
2641
2670
let mut builder =
2642
2671
PrimitiveDictionaryBuilder :: < Int8Type , Int32Type > :: with_capacity ( 1 , 1 ) ;
@@ -2670,6 +2699,7 @@ mod tests {
2670
2699
}
2671
2700
2672
2701
#[ test]
2702
+ #[ cfg( feature = "dyn_arith_dict" ) ]
2673
2703
fn test_dictionary_mul_dyn_wrapping_overflow ( ) {
2674
2704
let mut builder =
2675
2705
PrimitiveDictionaryBuilder :: < Int8Type , Int32Type > :: with_capacity ( 1 , 1 ) ;
@@ -2703,6 +2733,7 @@ mod tests {
2703
2733
}
2704
2734
2705
2735
#[ test]
2736
+ #[ cfg( feature = "dyn_arith_dict" ) ]
2706
2737
fn test_dictionary_div_dyn_wrapping_overflow ( ) {
2707
2738
let mut builder =
2708
2739
PrimitiveDictionaryBuilder :: < Int8Type , Int32Type > :: with_capacity ( 1 , 1 ) ;
0 commit comments