viirya commented on code in PR #2809:
URL: https://github.com/apache/arrow-rs/pull/2809#discussion_r990716175
##########
arrow-array/src/cast.rs:
##########
@@ -50,427 +62,183 @@ macro_rules! downcast_primitive_array {
($values:ident => $e:expr, $($p:pat => $fallback:expr $(,)*)*) => {
downcast_primitive_array!($values => {$e} $($p => $fallback)*)
};
-
- ($values:ident => $e:block $($p:pat => $fallback:expr $(,)*)*) => {
- match $values.data_type() {
- arrow_schema::DataType::Int8 => {
- let $values = $crate::cast::as_primitive_array::<
+ (($($values:ident),+) => $e:block $($($p:pat),+ => $fallback:expr $(,)*)*)
=> {
+ $crate::downcast_primitive_array!($($values),+ => $e $($($p),+ =>
$fallback)*)
+ };
+ (($($values:ident),+) => $e:block $(($($p:pat),+) => $fallback:expr
$(,)*)*) => {
+ $crate::downcast_primitive_array!($($values),+ => $e $($($p),+ =>
$fallback)*)
+ };
+ ($($values:ident),+ => $e:block $($($p:pat),+ => $fallback:expr $(,)*)*)
=> {
Review Comment:
The number of `$p:pat` might be different to `$values:ident` and that will
cause error. But the caller should take care of it.
##########
arrow-array/src/cast.rs:
##########
@@ -50,427 +62,183 @@ macro_rules! downcast_primitive_array {
($values:ident => $e:expr, $($p:pat => $fallback:expr $(,)*)*) => {
downcast_primitive_array!($values => {$e} $($p => $fallback)*)
};
-
- ($values:ident => $e:block $($p:pat => $fallback:expr $(,)*)*) => {
- match $values.data_type() {
- arrow_schema::DataType::Int8 => {
- let $values = $crate::cast::as_primitive_array::<
+ (($($values:ident),+) => $e:block $($($p:pat),+ => $fallback:expr $(,)*)*)
=> {
+ $crate::downcast_primitive_array!($($values),+ => $e $($($p),+ =>
$fallback)*)
+ };
+ (($($values:ident),+) => $e:block $(($($p:pat),+) => $fallback:expr
$(,)*)*) => {
+ $crate::downcast_primitive_array!($($values),+ => $e $($($p),+ =>
$fallback)*)
+ };
Review Comment:
What's the difference between this and below? With additional `(` `)`?
##########
arrow-array/src/cast.rs:
##########
@@ -20,6 +20,18 @@
use crate::array::*;
use crate::types::*;
+/// Repeats the provided pattern based on the number of comma separated
identifiers
+#[doc(hidden)]
+#[macro_export]
+macro_rules! repeat_pat {
+ ($e:pat, $v_:ident) => {
+ $e
+ };
+ ($e:pat, $v_:ident $(, $tail:ident)+) => {
+ ($e, $crate::repeat_pat!($e $(, $tail)+))
+ }
+}
Review Comment:
Oh, this is interesting. Nice. 👍
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]