Skip to content

Commit 454810b

Browse files
committed
improve the macro rules for impl_primitive_form_variant for timestamp
1 parent 807ac5c commit 454810b

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

parquet-variant-compute/src/type_conversion.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -56,15 +56,15 @@ macro_rules! impl_primitive_from_variant {
5656
}
5757
}
5858
};
59-
($arrow_type:ty $(, $variant_method:ident => $cast_fn:expr )+ ) => {
59+
($arrow_type:ty, $( $variant_type:pat => $variant_method:ident, $cast_fn:expr ),+ $(,)?) => {
6060
impl TimestampFromVariant for $arrow_type {
6161
fn from_variant(variant: &Variant<'_, '_>) -> Option<Self::Native> {
62-
$(
63-
if let Some(value) = variant.$variant_method() {
64-
return Some($cast_fn(value));
65-
}
66-
)+
67-
None
62+
match variant {
63+
$(
64+
$variant_type => variant.$variant_method().map($cast_fn),
65+
)+
66+
_ => None
67+
}
6868
}
6969
}
7070
};
@@ -88,11 +88,11 @@ impl_primitive_from_variant!(
8888
);
8989
impl_primitive_from_variant!(
9090
datatypes::TimestampMicrosecondType,
91-
as_timestamp_micros => |t| t);
91+
Variant::TimestampNtzMicros(_) | Variant::TimestampMicros(_) => as_timestamp_micros, |t| t);
9292
impl_primitive_from_variant!(
9393
datatypes::TimestampNanosecondType,
94-
as_timestamp_micros => |t| 1000 * t,
95-
as_timestamp_nanos => |t| t);
94+
Variant::TimestampNtzMicros(_) | Variant::TimestampMicros(_) => as_timestamp_micros, |t| 1000 * t,
95+
Variant::TimestampNtzNanos(_) | Variant::TimestampNanos(_) => as_timestamp_nanos, |t| t);
9696

9797
/// Convert the value at a specific index in the given array into a `Variant`.
9898
macro_rules! non_generic_conversion_single_value {

0 commit comments

Comments
 (0)