@@ -252,13 +252,25 @@ fn collect_new_statistics(
252252 } ,
253253 ) | {
254254 let closed_interval = interval. close_bounds ( ) ;
255+ let ( min_value, max_value) =
256+ if closed_interval. lower . value . eq ( & closed_interval. upper . value ) {
257+ (
258+ Precision :: Exact ( closed_interval. lower . value ) ,
259+ Precision :: Exact ( closed_interval. upper . value ) ,
260+ )
261+ } else {
262+ (
263+ Precision :: Inexact ( closed_interval. lower . value ) ,
264+ Precision :: Inexact ( closed_interval. upper . value ) ,
265+ )
266+ } ;
255267 ColumnStatistics {
256268 null_count : match input_column_stats[ idx] . null_count . get_value ( ) {
257269 Some ( nc) => Precision :: Inexact ( * nc) ,
258270 None => Precision :: Absent ,
259271 } ,
260- max_value : Precision :: Inexact ( closed_interval . upper . value ) ,
261- min_value : Precision :: Inexact ( closed_interval . lower . value ) ,
272+ max_value,
273+ min_value,
262274 distinct_count : match distinct_count. get_value ( ) {
263275 Some ( dc) => Precision :: Inexact ( * dc) ,
264276 None => Precision :: Absent ,
@@ -963,4 +975,26 @@ mod tests {
963975
964976 Ok ( ( ) )
965977 }
978+
979+ #[ tokio:: test]
980+ async fn test_statistics_with_constant_column ( ) -> Result < ( ) > {
981+ let schema = Schema :: new ( vec ! [ Field :: new( "a" , DataType :: Int32 , false ) ] ) ;
982+ let input = Arc :: new ( StatisticsExec :: new (
983+ Statistics :: new_unknown ( & schema) ,
984+ schema,
985+ ) ) ;
986+ // WHERE a = 10
987+ let predicate = Arc :: new ( BinaryExpr :: new (
988+ Arc :: new ( Column :: new ( "a" , 0 ) ) ,
989+ Operator :: Eq ,
990+ Arc :: new ( Literal :: new ( ScalarValue :: Int32 ( Some ( 10 ) ) ) ) ,
991+ ) ) ;
992+ let filter: Arc < dyn ExecutionPlan > =
993+ Arc :: new ( FilterExec :: try_new ( predicate, input) ?) ;
994+ let filter_statistics = filter. statistics ( ) ?;
995+ // First column is "a", and it is a column with only one value after the filter.
996+ assert ! ( filter_statistics. column_statistics[ 0 ] . is_singleton( ) ) ;
997+
998+ Ok ( ( ) )
999+ }
9661000}
0 commit comments