@@ -60,6 +60,8 @@ macro_rules! repeat_pat {
60
60
/// k.as_ref() => (dictionary_key_size_helper, u8),
61
61
/// _ => unreachable!(),
62
62
/// },
63
+ /// // You can also add a guard to the pattern
64
+ /// DataType::LargeUtf8 if true => u8::MAX,
63
65
/// _ => u8::MAX,
64
66
/// }
65
67
/// }
@@ -72,7 +74,7 @@ macro_rules! repeat_pat {
72
74
/// [`DataType`]: arrow_schema::DataType
73
75
#[ macro_export]
74
76
macro_rules! downcast_integer {
75
- ( $( $data_type: expr) ,+ => ( $m: path $( , $args: tt) * ) , $( $p: pat => $fallback: expr $( , ) * ) * ) => {
77
+ ( $( $data_type: expr) ,+ => ( $m: path $( , $args: tt) * ) , $( $p: pat $ ( if $pred : expr ) * => $fallback: expr $( , ) * ) * ) => {
76
78
match ( $( $data_type) ,+) {
77
79
$crate:: repeat_pat!( $crate:: cast:: __private:: DataType :: Int8 , $( $data_type) ,+) => {
78
80
$m!( $crate:: types:: Int8Type $( , $args) * )
@@ -98,7 +100,7 @@ macro_rules! downcast_integer {
98
100
$crate:: repeat_pat!( $crate:: cast:: __private:: DataType :: UInt64 , $( $data_type) ,+) => {
99
101
$m!( $crate:: types:: UInt64Type $( , $args) * )
100
102
}
101
- $( $p => $fallback, ) *
103
+ $( $p $ ( if $pred ) * => $fallback, ) *
102
104
}
103
105
} ;
104
106
}
@@ -107,7 +109,7 @@ macro_rules! downcast_integer {
107
109
/// with the corresponding array, along with match statements for any non integer array types
108
110
///
109
111
/// ```
110
- /// # use arrow_array::{Array, downcast_integer_array, cast::as_string_array};
112
+ /// # use arrow_array::{Array, downcast_integer_array, cast::as_string_array, cast::as_largestring_array };
111
113
/// # use arrow_schema::DataType;
112
114
///
113
115
/// fn print_integer(array: &dyn Array) {
@@ -122,6 +124,12 @@ macro_rules! downcast_integer {
122
124
/// println!("{:?}", v);
123
125
/// }
124
126
/// }
127
+ /// // You can also add a guard to the pattern
128
+ /// DataType::LargeUtf8 if true => {
129
+ /// for v in as_largestring_array(array) {
130
+ /// println!("{:?}", v);
131
+ /// }
132
+ /// }
125
133
/// t => println!("Unsupported datatype {}", t)
126
134
/// )
127
135
/// }
@@ -130,19 +138,19 @@ macro_rules! downcast_integer {
130
138
/// [`DataType`]: arrow_schema::DataType
131
139
#[ macro_export]
132
140
macro_rules! downcast_integer_array {
133
- ( $values: ident => $e: expr, $( $p: pat => $fallback: expr $( , ) * ) * ) => {
134
- $crate:: downcast_integer_array!( $values => { $e} $( $p => $fallback) * )
141
+ ( $values: ident => $e: expr, $( $p: pat $ ( if $pred : expr ) * => $fallback: expr $( , ) * ) * ) => {
142
+ $crate:: downcast_integer_array!( $values => { $e} $( $p $ ( if $pred ) * => $fallback) * )
135
143
} ;
136
- ( ( $( $values: ident) ,+) => $e: expr, $( $p: pat => $fallback: expr $( , ) * ) * ) => {
137
- $crate:: downcast_integer_array!( $( $values) ,+ => { $e} $( $p => $fallback) * )
144
+ ( ( $( $values: ident) ,+) => $e: expr, $( $p: pat $ ( if $pred : expr ) * => $fallback: expr $( , ) * ) * ) => {
145
+ $crate:: downcast_integer_array!( $( $values) ,+ => { $e} $( $p $ ( if $pred ) * => $fallback) * )
138
146
} ;
139
- ( $( $values: ident) ,+ => $e: block $( $p: pat => $fallback: expr $( , ) * ) * ) => {
140
- $crate:: downcast_integer_array!( ( $( $values) ,+) => $e $( $p => $fallback) * )
147
+ ( $( $values: ident) ,+ => $e: block $( $p: pat $ ( if $pred : expr ) * => $fallback: expr $( , ) * ) * ) => {
148
+ $crate:: downcast_integer_array!( ( $( $values) ,+) => $e $( $p $ ( if $pred ) * => $fallback) * )
141
149
} ;
142
- ( ( $( $values: ident) ,+) => $e: block $( $p: pat => $fallback: expr $( , ) * ) * ) => {
150
+ ( ( $( $values: ident) ,+) => $e: block $( $p: pat $ ( if $pred : expr ) * => $fallback: expr $( , ) * ) * ) => {
143
151
$crate:: downcast_integer!{
144
152
$( $values. data_type( ) ) ,+ => ( $crate:: downcast_primitive_array_helper, $( $values) ,+, $e) ,
145
- $( $p => $fallback, ) *
153
+ $( $p $ ( if $pred ) * => $fallback, ) *
146
154
}
147
155
} ;
148
156
}
@@ -167,6 +175,8 @@ macro_rules! downcast_integer_array {
167
175
/// k.data_type() => (run_end_size_helper, u8),
168
176
/// _ => unreachable!(),
169
177
/// },
178
+ /// // You can also add a guard to the pattern
179
+ /// DataType::LargeUtf8 if true => u8::MAX,
170
180
/// _ => u8::MAX,
171
181
/// }
172
182
/// }
@@ -179,7 +189,7 @@ macro_rules! downcast_integer_array {
179
189
/// [`DataType`]: arrow_schema::DataType
180
190
#[ macro_export]
181
191
macro_rules! downcast_run_end_index {
182
- ( $( $data_type: expr) ,+ => ( $m: path $( , $args: tt) * ) , $( $p: pat => $fallback: expr $( , ) * ) * ) => {
192
+ ( $( $data_type: expr) ,+ => ( $m: path $( , $args: tt) * ) , $( $p: pat $ ( if $pred : expr ) * => $fallback: expr $( , ) * ) * ) => {
183
193
match ( $( $data_type) ,+) {
184
194
$crate:: repeat_pat!( $crate:: cast:: __private:: DataType :: Int16 , $( $data_type) ,+) => {
185
195
$m!( $crate:: types:: Int16Type $( , $args) * )
@@ -190,7 +200,7 @@ macro_rules! downcast_run_end_index {
190
200
$crate:: repeat_pat!( $crate:: cast:: __private:: DataType :: Int64 , $( $data_type) ,+) => {
191
201
$m!( $crate:: types:: Int64Type $( , $args) * )
192
202
}
193
- $( $p => $fallback, ) *
203
+ $( $p $ ( if $pred ) * => $fallback, ) *
194
204
}
195
205
} ;
196
206
}
@@ -211,6 +221,8 @@ macro_rules! downcast_run_end_index {
211
221
/// fn temporal_size(t: &DataType) -> u8 {
212
222
/// downcast_temporal! {
213
223
/// t => (temporal_size_helper, u8),
224
+ /// // You can also add a guard to the pattern
225
+ /// DataType::LargeUtf8 if true => u8::MAX,
214
226
/// _ => u8::MAX
215
227
/// }
216
228
/// }
@@ -222,7 +234,7 @@ macro_rules! downcast_run_end_index {
222
234
/// [`DataType`]: arrow_schema::DataType
223
235
#[ macro_export]
224
236
macro_rules! downcast_temporal {
225
- ( $( $data_type: expr) ,+ => ( $m: path $( , $args: tt) * ) , $( $p: pat => $fallback: expr $( , ) * ) * ) => {
237
+ ( $( $data_type: expr) ,+ => ( $m: path $( , $args: tt) * ) , $( $p: pat $ ( if $pred : expr ) * => $fallback: expr $( , ) * ) * ) => {
226
238
match ( $( $data_type) ,+) {
227
239
$crate:: repeat_pat!( $crate:: cast:: __private:: DataType :: Time32 ( $crate:: cast:: __private:: TimeUnit :: Second ) , $( $data_type) ,+) => {
228
240
$m!( $crate:: types:: Time32SecondType $( , $args) * )
@@ -254,7 +266,7 @@ macro_rules! downcast_temporal {
254
266
$crate:: repeat_pat!( $crate:: cast:: __private:: DataType :: Timestamp ( $crate:: cast:: __private:: TimeUnit :: Nanosecond , _) , $( $data_type) ,+) => {
255
267
$m!( $crate:: types:: TimestampNanosecondType $( , $args) * )
256
268
}
257
- $( $p => $fallback, ) *
269
+ $( $p $ ( if $pred ) * => $fallback, ) *
258
270
}
259
271
} ;
260
272
}
@@ -263,7 +275,7 @@ macro_rules! downcast_temporal {
263
275
/// accepts a number of subsequent patterns to match the data type
264
276
///
265
277
/// ```
266
- /// # use arrow_array::{Array, downcast_temporal_array, cast::as_string_array};
278
+ /// # use arrow_array::{Array, downcast_temporal_array, cast::as_string_array, cast::as_largestring_array };
267
279
/// # use arrow_schema::DataType;
268
280
///
269
281
/// fn print_temporal(array: &dyn Array) {
@@ -278,6 +290,12 @@ macro_rules! downcast_temporal {
278
290
/// println!("{:?}", v);
279
291
/// }
280
292
/// }
293
+ /// // You can also add a guard to the pattern
294
+ /// DataType::LargeUtf8 if true => {
295
+ /// for v in as_largestring_array(array) {
296
+ /// println!("{:?}", v);
297
+ /// }
298
+ /// }
281
299
/// t => println!("Unsupported datatype {}", t)
282
300
/// )
283
301
/// }
@@ -286,19 +304,19 @@ macro_rules! downcast_temporal {
286
304
/// [`DataType`]: arrow_schema::DataType
287
305
#[ macro_export]
288
306
macro_rules! downcast_temporal_array {
289
- ( $values: ident => $e: expr, $( $p: pat => $fallback: expr $( , ) * ) * ) => {
290
- $crate:: downcast_temporal_array!( $values => { $e} $( $p => $fallback) * )
307
+ ( $values: ident => $e: expr, $( $p: pat $ ( if $pred : expr ) * => $fallback: expr $( , ) * ) * ) => {
308
+ $crate:: downcast_temporal_array!( $values => { $e} $( $p $ ( if $pred ) * => $fallback) * )
291
309
} ;
292
- ( ( $( $values: ident) ,+) => $e: expr, $( $p: pat => $fallback: expr $( , ) * ) * ) => {
293
- $crate:: downcast_temporal_array!( $( $values) ,+ => { $e} $( $p => $fallback) * )
310
+ ( ( $( $values: ident) ,+) => $e: expr, $( $p: pat $ ( if $pred : expr ) * => $fallback: expr $( , ) * ) * ) => {
311
+ $crate:: downcast_temporal_array!( $( $values) ,+ => { $e} $( $p $ ( if $pred ) * => $fallback) * )
294
312
} ;
295
- ( $( $values: ident) ,+ => $e: block $( $p: pat => $fallback: expr $( , ) * ) * ) => {
296
- $crate:: downcast_temporal_array!( ( $( $values) ,+) => $e $( $p => $fallback) * )
313
+ ( $( $values: ident) ,+ => $e: block $( $p: pat $ ( if $pred : expr ) * => $fallback: expr $( , ) * ) * ) => {
314
+ $crate:: downcast_temporal_array!( ( $( $values) ,+) => $e $( $p $ ( if $pred ) * => $fallback) * )
297
315
} ;
298
- ( ( $( $values: ident) ,+) => $e: block $( $p: pat => $fallback: expr $( , ) * ) * ) => {
316
+ ( ( $( $values: ident) ,+) => $e: block $( $p: pat $ ( if $pred : expr ) * => $fallback: expr $( , ) * ) * ) => {
299
317
$crate:: downcast_temporal!{
300
318
$( $values. data_type( ) ) ,+ => ( $crate:: downcast_primitive_array_helper, $( $values) ,+, $e) ,
301
- $( $p => $fallback, ) *
319
+ $( $p $ ( if $pred ) * => $fallback, ) *
302
320
}
303
321
} ;
304
322
}
@@ -319,6 +337,8 @@ macro_rules! downcast_temporal_array {
319
337
/// fn primitive_size(t: &DataType) -> u8 {
320
338
/// downcast_primitive! {
321
339
/// t => (primitive_size_helper, u8),
340
+ /// // You can also add a guard to the pattern
341
+ /// DataType::LargeUtf8 if true => u8::MAX,
322
342
/// _ => u8::MAX
323
343
/// }
324
344
/// }
@@ -333,7 +353,7 @@ macro_rules! downcast_temporal_array {
333
353
/// [`DataType`]: arrow_schema::DataType
334
354
#[ macro_export]
335
355
macro_rules! downcast_primitive {
336
- ( $( $data_type: expr) ,+ => ( $m: path $( , $args: tt) * ) , $( $p: pat => $fallback: expr $( , ) * ) * ) => {
356
+ ( $( $data_type: expr) ,+ => ( $m: path $( , $args: tt) * ) , $( $p: pat $ ( if $pred : expr ) * => $fallback: expr $( , ) * ) * ) => {
337
357
$crate:: downcast_integer! {
338
358
$( $data_type) ,+ => ( $m $( , $args) * ) ,
339
359
$crate:: repeat_pat!( $crate:: cast:: __private:: DataType :: Float16 , $( $data_type) ,+) => {
@@ -375,7 +395,7 @@ macro_rules! downcast_primitive {
375
395
_ => {
376
396
$crate:: downcast_temporal! {
377
397
$( $data_type) ,+ => ( $m $( , $args) * ) ,
378
- $( $p => $fallback, ) *
398
+ $( $p $ ( if $pred ) * => $fallback, ) *
379
399
}
380
400
}
381
401
}
@@ -395,7 +415,7 @@ macro_rules! downcast_primitive_array_helper {
395
415
/// accepts a number of subsequent patterns to match the data type
396
416
///
397
417
/// ```
398
- /// # use arrow_array::{Array, downcast_primitive_array, cast::as_string_array};
418
+ /// # use arrow_array::{Array, downcast_primitive_array, cast::as_string_array, cast::as_largestring_array };
399
419
/// # use arrow_schema::DataType;
400
420
///
401
421
/// fn print_primitive(array: &dyn Array) {
@@ -410,6 +430,12 @@ macro_rules! downcast_primitive_array_helper {
410
430
/// println!("{:?}", v);
411
431
/// }
412
432
/// }
433
+ /// // You can also add a guard to the pattern
434
+ /// DataType::LargeUtf8 if true => {
435
+ /// for v in as_largestring_array(array) {
436
+ /// println!("{:?}", v);
437
+ /// }
438
+ /// }
413
439
/// t => println!("Unsupported datatype {}", t)
414
440
/// )
415
441
/// }
@@ -418,19 +444,19 @@ macro_rules! downcast_primitive_array_helper {
418
444
/// [`DataType`]: arrow_schema::DataType
419
445
#[ macro_export]
420
446
macro_rules! downcast_primitive_array {
421
- ( $values: ident => $e: expr, $( $p: pat => $fallback: expr $( , ) * ) * ) => {
422
- $crate:: downcast_primitive_array!( $values => { $e} $( $p => $fallback) * )
447
+ ( $values: ident => $e: expr, $( $p: pat $ ( if $pred : expr ) * => $fallback: expr $( , ) * ) * ) => {
448
+ $crate:: downcast_primitive_array!( $values => { $e} $( $p $ ( if $pred ) * => $fallback) * )
423
449
} ;
424
- ( ( $( $values: ident) ,+) => $e: expr, $( $p: pat => $fallback: expr $( , ) * ) * ) => {
425
- $crate:: downcast_primitive_array!( $( $values) ,+ => { $e} $( $p => $fallback) * )
450
+ ( ( $( $values: ident) ,+) => $e: expr, $( $p: pat $ ( if $pred : expr ) * => $fallback: expr $( , ) * ) * ) => {
451
+ $crate:: downcast_primitive_array!( $( $values) ,+ => { $e} $( $p $ ( if $pred ) * => $fallback) * )
426
452
} ;
427
- ( $( $values: ident) ,+ => $e: block $( $p: pat => $fallback: expr $( , ) * ) * ) => {
428
- $crate:: downcast_primitive_array!( ( $( $values) ,+) => $e $( $p => $fallback) * )
453
+ ( $( $values: ident) ,+ => $e: block $( $p: pat $ ( if $pred : expr ) * => $fallback: expr $( , ) * ) * ) => {
454
+ $crate:: downcast_primitive_array!( ( $( $values) ,+) => $e $( $p $ ( if $pred ) * => $fallback) * )
429
455
} ;
430
- ( ( $( $values: ident) ,+) => $e: block $( $p: pat => $fallback: expr $( , ) * ) * ) => {
456
+ ( ( $( $values: ident) ,+) => $e: block $( $p: pat $ ( if $pred : expr ) * => $fallback: expr $( , ) * ) * ) => {
431
457
$crate:: downcast_primitive!{
432
458
$( $values. data_type( ) ) ,+ => ( $crate:: downcast_primitive_array_helper, $( $values) ,+, $e) ,
433
- $( $p => $fallback, ) *
459
+ $( $p $ ( if $pred ) * => $fallback, ) *
434
460
}
435
461
} ;
436
462
}
@@ -482,7 +508,7 @@ macro_rules! downcast_dictionary_array_helper {
482
508
/// a number of subsequent patterns to match the data type
483
509
///
484
510
/// ```
485
- /// # use arrow_array::{Array, StringArray, downcast_dictionary_array, cast::as_string_array};
511
+ /// # use arrow_array::{Array, StringArray, downcast_dictionary_array, cast::as_string_array, cast::as_largestring_array };
486
512
/// # use arrow_schema::DataType;
487
513
///
488
514
/// fn print_strings(array: &dyn Array) {
@@ -500,6 +526,12 @@ macro_rules! downcast_dictionary_array_helper {
500
526
/// println!("{:?}", v);
501
527
/// }
502
528
/// }
529
+ /// // You can also add a guard to the pattern
530
+ /// DataType::LargeUtf8 if true => {
531
+ /// for v in as_largestring_array(array) {
532
+ /// println!("{:?}", v);
533
+ /// }
534
+ /// }
503
535
/// t => println!("Unsupported datatype {}", t)
504
536
/// )
505
537
/// }
@@ -508,19 +540,19 @@ macro_rules! downcast_dictionary_array_helper {
508
540
/// [`DataType`]: arrow_schema::DataType
509
541
#[ macro_export]
510
542
macro_rules! downcast_dictionary_array {
511
- ( $values: ident => $e: expr, $( $p: pat => $fallback: expr $( , ) * ) * ) => {
512
- downcast_dictionary_array!( $values => { $e} $( $p => $fallback) * )
543
+ ( $values: ident => $e: expr, $( $p: pat $ ( if $pred : expr ) * => $fallback: expr $( , ) * ) * ) => {
544
+ downcast_dictionary_array!( $values => { $e} $( $p $ ( if $pred ) * => $fallback) * )
513
545
} ;
514
546
515
- ( $values: ident => $e: block $( $p: pat => $fallback: expr $( , ) * ) * ) => {
547
+ ( $values: ident => $e: block $( $p: pat $ ( if $pred : expr ) * => $fallback: expr $( , ) * ) * ) => {
516
548
match $values. data_type( ) {
517
549
$crate:: cast:: __private:: DataType :: Dictionary ( k, _) => {
518
550
$crate:: downcast_integer! {
519
551
k. as_ref( ) => ( $crate:: downcast_dictionary_array_helper, $values, $e) ,
520
552
k => unreachable!( "unsupported dictionary key type: {}" , k)
521
553
}
522
554
}
523
- $( $p => $fallback, ) *
555
+ $( $p $ ( if $pred ) * => $fallback, ) *
524
556
}
525
557
}
526
558
}
@@ -584,7 +616,7 @@ macro_rules! downcast_run_array_helper {
584
616
/// a number of subsequent patterns to match the data type
585
617
///
586
618
/// ```
587
- /// # use arrow_array::{Array, StringArray, downcast_run_array, cast::as_string_array};
619
+ /// # use arrow_array::{Array, StringArray, downcast_run_array, cast::as_string_array, cast::as_largestring_array };
588
620
/// # use arrow_schema::DataType;
589
621
///
590
622
/// fn print_strings(array: &dyn Array) {
@@ -602,6 +634,12 @@ macro_rules! downcast_run_array_helper {
602
634
/// println!("{:?}", v);
603
635
/// }
604
636
/// }
637
+ /// // You can also add a guard to the pattern
638
+ /// DataType::LargeUtf8 if true => {
639
+ /// for v in as_largestring_array(array) {
640
+ /// println!("{:?}", v);
641
+ /// }
642
+ /// }
605
643
/// t => println!("Unsupported datatype {}", t)
606
644
/// )
607
645
/// }
@@ -610,19 +648,19 @@ macro_rules! downcast_run_array_helper {
610
648
/// [`DataType`]: arrow_schema::DataType
611
649
#[ macro_export]
612
650
macro_rules! downcast_run_array {
613
- ( $values: ident => $e: expr, $( $p: pat => $fallback: expr $( , ) * ) * ) => {
614
- downcast_run_array!( $values => { $e} $( $p => $fallback) * )
651
+ ( $values: ident => $e: expr, $( $p: pat $ ( if $pred : expr ) * => $fallback: expr $( , ) * ) * ) => {
652
+ downcast_run_array!( $values => { $e} $( $p $ ( if $pred ) * => $fallback) * )
615
653
} ;
616
654
617
- ( $values: ident => $e: block $( $p: pat => $fallback: expr $( , ) * ) * ) => {
655
+ ( $values: ident => $e: block $( $p: pat $ ( if $pred : expr ) * => $fallback: expr $( , ) * ) * ) => {
618
656
match $values. data_type( ) {
619
657
$crate:: cast:: __private:: DataType :: RunEndEncoded ( k, _) => {
620
658
$crate:: downcast_run_end_index! {
621
659
k. data_type( ) => ( $crate:: downcast_run_array_helper, $values, $e) ,
622
660
k => unreachable!( "unsupported run end index type: {}" , k)
623
661
}
624
662
}
625
- $( $p => $fallback, ) *
663
+ $( $p $ ( if $pred ) * => $fallback, ) *
626
664
}
627
665
}
628
666
}
0 commit comments