@@ -665,54 +665,70 @@ pub(crate) fn get_arrow_datum(datum: &Datum) -> Result<Box<dyn ArrowDatum + Send
665
665
}
666
666
667
667
macro_rules! get_parquet_stat_as_datum {
668
- ( $limit_type: ident ) => {
668
+ ( $limit_type: tt ) => {
669
669
paste:: paste! {
670
670
/// Gets the $limit_type value from a parquet Statistics struct, as a Datum
671
671
pub ( crate ) fn [ <get_parquet_stat_ $limit_type _as_datum>] (
672
672
primitive_type: & PrimitiveType , stats: & Statistics
673
673
) -> Result <Option <Datum >> {
674
- Ok ( Some ( match ( primitive_type, stats) {
675
- ( PrimitiveType :: Boolean , Statistics :: Boolean ( stats) ) => Datum :: bool ( * stats. $limit_type( ) ) ,
676
- ( PrimitiveType :: Int , Statistics :: Int32 ( stats) ) => Datum :: int( * stats. $limit_type( ) ) ,
677
- ( PrimitiveType :: Date , Statistics :: Int32 ( stats) ) => Datum :: date( * stats. $limit_type( ) ) ,
678
- ( PrimitiveType :: Long , Statistics :: Int64 ( stats) ) => Datum :: long( * stats. $limit_type( ) ) ,
679
- ( PrimitiveType :: Time , Statistics :: Int64 ( stats) ) => Datum :: time_micros( * stats. $limit_type( ) ) ?,
674
+ Ok ( match ( primitive_type, stats) {
675
+ ( PrimitiveType :: Boolean , Statistics :: Boolean ( stats) ) => stats. [ <$limit_type _opt>] ( ) . map( |val|Datum :: bool ( * val) ) ,
676
+ ( PrimitiveType :: Int , Statistics :: Int32 ( stats) ) => stats. [ <$limit_type _opt>] ( ) . map( |val|Datum :: int( * val) ) ,
677
+ ( PrimitiveType :: Date , Statistics :: Int32 ( stats) ) => stats. [ <$limit_type _opt>] ( ) . map( |val|Datum :: date( * val) ) ,
678
+ ( PrimitiveType :: Long , Statistics :: Int64 ( stats) ) => stats. [ <$limit_type _opt>] ( ) . map( |val|Datum :: long( * val) ) ,
679
+ ( PrimitiveType :: Time , Statistics :: Int64 ( stats) ) => {
680
+ let Some ( val) = stats. [ <$limit_type _opt>] ( ) else {
681
+ return Ok ( None ) ;
682
+ } ;
683
+
684
+ Some ( Datum :: time_micros( * val) ?)
685
+ }
680
686
( PrimitiveType :: Timestamp , Statistics :: Int64 ( stats) ) => {
681
- Datum :: timestamp_micros( * stats . $limit_type ( ) )
687
+ stats . [ <$limit_type _opt> ] ( ) . map ( |val| Datum :: timestamp_micros( * val ) )
682
688
}
683
689
( PrimitiveType :: Timestamptz , Statistics :: Int64 ( stats) ) => {
684
- Datum :: timestamptz_micros( * stats . $limit_type ( ) )
690
+ stats . [ <$limit_type _opt> ] ( ) . map ( |val| Datum :: timestamptz_micros( * val ) )
685
691
}
686
692
( PrimitiveType :: TimestampNs , Statistics :: Int64 ( stats) ) => {
687
- Datum :: timestamp_nanos( * stats . $limit_type ( ) )
693
+ stats . [ <$limit_type _opt> ] ( ) . map ( |val| Datum :: timestamp_nanos( * val ) )
688
694
}
689
695
( PrimitiveType :: TimestamptzNs , Statistics :: Int64 ( stats) ) => {
690
- Datum :: timestamptz_nanos( * stats . $limit_type ( ) )
696
+ stats . [ <$limit_type _opt> ] ( ) . map ( |val| Datum :: timestamptz_nanos( * val ) )
691
697
}
692
- ( PrimitiveType :: Float , Statistics :: Float ( stats) ) => Datum :: float( * stats . $limit_type ( ) ) ,
693
- ( PrimitiveType :: Double , Statistics :: Double ( stats) ) => Datum :: double( * stats . $limit_type ( ) ) ,
698
+ ( PrimitiveType :: Float , Statistics :: Float ( stats) ) => stats . [ <$limit_type _opt> ] ( ) . map ( |val| Datum :: float( * val ) ) ,
699
+ ( PrimitiveType :: Double , Statistics :: Double ( stats) ) => stats . [ <$limit_type _opt> ] ( ) . map ( |val| Datum :: double( * val ) ) ,
694
700
( PrimitiveType :: String , Statistics :: ByteArray ( stats) ) => {
695
- Datum :: string( stats. $limit_type( ) . as_utf8( ) ?)
701
+ let Some ( val) = stats. [ <$limit_type _opt>] ( ) else {
702
+ return Ok ( None ) ;
703
+ } ;
704
+
705
+ Some ( Datum :: string( val. as_utf8( ) ?) )
696
706
}
697
707
( PrimitiveType :: Decimal {
698
708
precision: _,
699
709
scale: _,
700
710
} , Statistics :: ByteArray ( stats) ) => {
701
- Datum :: new(
711
+ let Some ( bytes) = stats. [ <$limit_type _bytes_opt>] ( ) else {
712
+ return Ok ( None ) ;
713
+ } ;
714
+
715
+ Some ( Datum :: new(
702
716
primitive_type. clone( ) ,
703
- PrimitiveLiteral :: Int128 ( i128 :: from_le_bytes( stats . [ <$limit_type _bytes> ] ( ) . try_into( ) ?) ) ,
704
- )
717
+ PrimitiveLiteral :: Int128 ( i128 :: from_le_bytes( bytes . try_into( ) ?) ) ,
718
+ ) )
705
719
}
706
720
(
707
721
PrimitiveType :: Decimal {
708
722
precision: _,
709
723
scale: _,
710
724
} ,
711
725
Statistics :: Int32 ( stats) ) => {
712
- Datum :: new(
713
- primitive_type. clone( ) ,
714
- PrimitiveLiteral :: Int128 ( i128 :: from( * stats. $limit_type( ) ) ) ,
715
- )
726
+ stats. [ <$limit_type _opt>] ( ) . map( |val| {
727
+ Datum :: new(
728
+ primitive_type. clone( ) ,
729
+ PrimitiveLiteral :: Int128 ( i128 :: from( * val) ) ,
730
+ )
731
+ } )
716
732
}
717
733
718
734
(
@@ -722,40 +738,46 @@ macro_rules! get_parquet_stat_as_datum {
722
738
} ,
723
739
Statistics :: Int64 ( stats) ,
724
740
) => {
725
- Datum :: new(
726
- primitive_type. clone( ) ,
727
- PrimitiveLiteral :: Int128 ( i128 :: from( * stats. $limit_type( ) ) ) ,
728
- )
741
+ stats. [ <$limit_type _opt>] ( ) . map( |val| {
742
+ Datum :: new(
743
+ primitive_type. clone( ) ,
744
+ PrimitiveLiteral :: Int128 ( i128 :: from( * val) ) ,
745
+ )
746
+ } )
729
747
}
730
748
( PrimitiveType :: Uuid , Statistics :: FixedLenByteArray ( stats) ) => {
731
- let raw = stats. [ <$limit_type _bytes>] ( ) ;
732
- if raw. len( ) != 16 {
749
+ let Some ( bytes) = stats. [ <$limit_type _bytes_opt>] ( ) else {
750
+ return Ok ( None ) ;
751
+ } ;
752
+ if bytes. len( ) != 16 {
733
753
return Err ( Error :: new(
734
754
ErrorKind :: Unexpected ,
735
755
"Invalid length of uuid bytes." ,
736
756
) ) ;
737
757
}
738
- Datum :: uuid( Uuid :: from_bytes(
739
- raw [ ..16 ] . try_into( ) . unwrap( ) ,
740
- ) )
758
+ Some ( Datum :: uuid( Uuid :: from_bytes(
759
+ bytes [ ..16 ] . try_into( ) . unwrap( ) ,
760
+ ) ) )
741
761
}
742
762
( PrimitiveType :: Fixed ( len) , Statistics :: FixedLenByteArray ( stat) ) => {
743
- let raw = stat. [ <$limit_type _bytes>] ( ) ;
744
- if raw. len( ) != * len as usize {
763
+ let Some ( bytes) = stat. [ <$limit_type _bytes_opt>] ( ) else {
764
+ return Ok ( None ) ;
765
+ } ;
766
+ if bytes. len( ) != * len as usize {
745
767
return Err ( Error :: new(
746
768
ErrorKind :: Unexpected ,
747
769
"Invalid length of fixed bytes." ,
748
770
) ) ;
749
771
}
750
- Datum :: fixed( raw . to_vec( ) )
772
+ Some ( Datum :: fixed( bytes . to_vec( ) ) )
751
773
}
752
774
( PrimitiveType :: Binary , Statistics :: ByteArray ( stat) ) => {
753
- Datum :: binary ( stat. [ <$limit_type _bytes >] ( ) . to_vec( ) )
775
+ return Ok ( stat. [ <$limit_type _bytes_opt >] ( ) . map ( |bytes| Datum :: binary ( bytes . to_vec( ) ) ) )
754
776
}
755
777
_ => {
756
778
return Ok ( None ) ;
757
779
}
758
- } ) )
780
+ } )
759
781
}
760
782
}
761
783
}
0 commit comments