@@ -45,24 +45,27 @@ use futures::stream;
4545use object_store:: ObjectMeta ;
4646use object_store:: ObjectStore ;
4747use vortex:: VortexSessionDefault ;
48+ use vortex:: aggregate_fn:: AggregateFnVTableExt ;
49+ use vortex:: aggregate_fn:: EmptyOptions ;
50+ use vortex:: aggregate_fn:: NumericalAggregateOpts ;
51+ use vortex:: aggregate_fn:: fns:: is_constant:: IsConstant ;
52+ use vortex:: aggregate_fn:: fns:: max:: Max ;
53+ use vortex:: aggregate_fn:: fns:: min:: Min ;
54+ use vortex:: aggregate_fn:: fns:: null_count:: NullCount ;
55+ use vortex:: aggregate_fn:: fns:: uncompressed_size_in_bytes:: UncompressedSizeInBytes ;
4856use vortex:: array:: memory:: MemorySessionExt ;
49- use vortex:: dtype:: DType ;
5057use vortex:: dtype:: FieldPath ;
51- use vortex:: dtype:: Nullability ;
52- use vortex:: dtype:: PType ;
5358use vortex:: error:: VortexExpect ;
5459use vortex:: error:: VortexResult ;
5560use vortex:: error:: vortex_err;
5661use vortex:: expr:: stats:: Precision ;
57- use vortex:: expr:: stats:: Stat ;
5862use vortex:: file:: EOF_SIZE ;
5963use vortex:: file:: MAX_POSTSCRIPT_SIZE ;
6064use vortex:: file:: OpenOptionsSessionExt ;
6165use vortex:: file:: VORTEX_FILE_EXTENSION ;
6266use vortex:: io:: object_store:: ObjectStoreReadAt ;
6367use vortex:: io:: session:: RuntimeSessionExt ;
6468use vortex:: scalar:: Scalar ;
65- use vortex:: scalar:: ScalarValue as VortexScalarValue ;
6669use vortex:: session:: VortexSession ;
6770use vortex_arrow:: ArrowSessionExt ;
6871
@@ -658,7 +661,7 @@ impl FileFormat for VortexFormat {
658661 for field in table_schema. fields ( ) . iter ( ) {
659662 // If the column does not exist, continue. This can happen if the schema has evolved
660663 // but we have not yet updated the Vortex file.
661- let Some ( ( stats_set , stats_dtype ) ) =
664+ let Some ( ( aggregates , _ ) ) =
662665 file_stats. get_by_path ( & FieldPath :: from_name ( field. name ( ) . as_str ( ) ) )
663666 else {
664667 // The default sets all statistics to `Precision<Absent>`.
@@ -667,35 +670,33 @@ impl FileFormat for VortexFormat {
667670 } ;
668671
669672 // Update the total size in bytes.
670- let column_size =
671- stats_set. get_as :: < usize > ( Stat :: UncompressedSizeInBytes , & PType :: U64 . into ( ) ) ;
673+ let column_size = aggregates
674+ . get ( & UncompressedSizeInBytes . bind ( EmptyOptions ) )
675+ . and_then ( |size| usize:: try_from ( & size) . ok ( ) ) ;
672676
673677 let min = scalar_stat_to_df (
674- Stat :: Min ,
675- stats_set. get ( Stat :: Min ) ,
676- stats_dtype,
678+ aggregates. get ( & Min . bind ( NumericalAggregateOpts :: skip_nans ( ) ) ) ,
677679 field. data_type ( ) ,
678680 ) ;
679681
680682 let max = scalar_stat_to_df (
681- Stat :: Max ,
682- stats_set. get ( Stat :: Max ) ,
683- stats_dtype,
683+ aggregates. get ( & Max . bind ( NumericalAggregateOpts :: skip_nans ( ) ) ) ,
684684 field. data_type ( ) ,
685685 ) ;
686686
687- let null_count = stats_set. get_as :: < usize > ( Stat :: NullCount , & PType :: U64 . into ( ) ) ;
687+ let null_count = aggregates
688+ . get ( & NullCount . bind ( EmptyOptions ) )
689+ . and_then ( |count| usize:: try_from ( & count) . ok ( ) ) ;
688690
689691 column_statistics. push ( ColumnStatistics {
690692 null_count : null_count. to_df ( ) ,
691693 min_value : min,
692694 max_value : max,
693695 sum_value : DFPrecision :: Absent ,
694696 distinct_count : is_constant_to_distinct_count (
695- stats_set. get_as :: < bool > (
696- Stat :: IsConstant ,
697- & DType :: Bool ( Nullability :: NonNullable ) ,
698- ) ,
697+ aggregates
698+ . get ( & IsConstant . bind ( EmptyOptions ) )
699+ . and_then ( |is_constant| bool:: try_from ( & is_constant) . ok ( ) ) ,
699700 ) ,
700701 byte_size : column_size. to_df ( ) ,
701702 } )
@@ -768,23 +769,11 @@ impl FileFormat for VortexFormat {
768769}
769770
770771fn scalar_stat_to_df (
771- stat : Stat ,
772- value : Precision < VortexScalarValue > ,
773- stats_dtype : & DType ,
772+ value : Precision < Scalar > ,
774773 target_dtype : & DataType ,
775774) -> DFPrecision < DFScalarValue > {
776- let Some ( stat_dtype) = stat. dtype ( stats_dtype) else {
777- return DFPrecision :: Absent ;
778- } ;
779-
780775 value
781- . and_then ( |stat_value| {
782- let scalar = Scalar :: try_new ( stat_dtype, Some ( stat_value) )
783- . ok ( ) ?
784- . try_to_df ( )
785- . ok ( ) ?;
786- scalar. cast_to ( target_dtype) . ok ( )
787- } )
776+ . and_then ( |scalar| scalar. try_to_df ( ) . ok ( ) ?. cast_to ( target_dtype) . ok ( ) )
788777 . to_df ( )
789778}
790779
@@ -849,26 +838,18 @@ mod tests {
849838 fn test_scalar_stat_to_df_cast (
850839 #[ case] value : ScalarValue ,
851840 #[ case] expected : ScalarValue ,
852- #[ values( Stat :: Min , Stat :: Max ) ] stat : Stat ,
853841 #[ values( true , false ) ] exact : bool ,
854842 ) -> VortexResult < ( ) > {
855843 let session = VortexSession :: default ( ) ;
856844 let scalar = scalar_from_df ( & value, & session) ?;
857- let value = scalar
858- . value ( )
859- . cloned ( )
860- . ok_or_else ( || vortex_err ! ( "expected non-null scalar" ) ) ?;
861845 let target_dtype = expected. data_type ( ) ;
862846 let ( value, expected) = if exact {
863- ( Precision :: Exact ( value ) , DFPrecision :: Exact ( expected) )
847+ ( Precision :: Exact ( scalar ) , DFPrecision :: Exact ( expected) )
864848 } else {
865- ( Precision :: Inexact ( value ) , DFPrecision :: Inexact ( expected) )
849+ ( Precision :: Inexact ( scalar ) , DFPrecision :: Inexact ( expected) )
866850 } ;
867851
868- assert_eq ! (
869- scalar_stat_to_df( stat, value, scalar. dtype( ) , & target_dtype) ,
870- expected
871- ) ;
852+ assert_eq ! ( scalar_stat_to_df( value, & target_dtype) , expected) ;
872853 Ok ( ( ) )
873854 }
874855
@@ -886,16 +867,11 @@ mod tests {
886867 fn test_scalar_stat_to_df_failed_cast (
887868 #[ case] value : ScalarValue ,
888869 #[ case] target_dtype : DataType ,
889- #[ values( Stat :: Min , Stat :: Max ) ] stat : Stat ,
890870 ) -> VortexResult < ( ) > {
891871 let session = VortexSession :: default ( ) ;
892872 let scalar = scalar_from_df ( & value, & session) ?;
893- let value = scalar
894- . value ( )
895- . cloned ( )
896- . ok_or_else ( || vortex_err ! ( "expected non-null scalar" ) ) ?;
897873 assert_eq ! (
898- scalar_stat_to_df( stat , Precision :: Exact ( value ) , scalar. dtype ( ) , & target_dtype) ,
874+ scalar_stat_to_df( Precision :: Exact ( scalar) , & target_dtype) ,
899875 DFPrecision :: Absent
900876 ) ;
901877 Ok ( ( ) )
0 commit comments