@@ -150,15 +150,16 @@ mod test {
150150 // - null_count = 0 (partition values from paths are never null)
151151 // - min/max are the merged partition values across files in the group
152152 // - byte_size = num_rows * 4 (Date32 is 4 bytes per row)
153- // - distinct_count = Inexact(1) per partition file (single partition value per file),
154- // preserved via max() when merging stats across partitions
153+ // - distinct_count = Inexact(max_date - min_date + 1), derived from the
154+ // date range via interval analysis for temporal types
155155 let date32_byte_size = num_rows * 4 ;
156+ let distinct_dates = ( max_date - min_date + 1 ) as usize ;
156157 column_stats. push ( ColumnStatistics {
157158 null_count : Precision :: Exact ( 0 ) ,
158159 max_value : Precision :: Exact ( ScalarValue :: Date32 ( Some ( max_date) ) ) ,
159160 min_value : Precision :: Exact ( ScalarValue :: Date32 ( Some ( min_date) ) ) ,
160161 sum_value : Precision :: Absent ,
161- distinct_count : Precision :: Inexact ( 1 ) ,
162+ distinct_count : Precision :: Inexact ( distinct_dates ) ,
162163 byte_size : Precision :: Exact ( date32_byte_size) ,
163164 } ) ;
164165 }
@@ -579,7 +580,7 @@ mod test {
579580 max_value: Precision :: Exact ( ScalarValue :: Date32 ( Some ( 20151 ) ) ) ,
580581 min_value: Precision :: Exact ( ScalarValue :: Date32 ( Some ( 20148 ) ) ) ,
581582 sum_value: Precision :: Absent ,
582- distinct_count: Precision :: Inexact ( 1 ) ,
583+ distinct_count: Precision :: Inexact ( 4 ) ,
583584 byte_size: Precision :: Absent ,
584585 } ,
585586 // column 2: right.id (Int32, file column from t2) - right partition 0: ids [3,4]
@@ -613,7 +614,7 @@ mod test {
613614 max_value: Precision :: Exact ( ScalarValue :: Date32 ( Some ( 20151 ) ) ) ,
614615 min_value: Precision :: Exact ( ScalarValue :: Date32 ( Some ( 20148 ) ) ) ,
615616 sum_value: Precision :: Absent ,
616- distinct_count: Precision :: Inexact ( 1 ) ,
617+ distinct_count: Precision :: Inexact ( 4 ) ,
617618 byte_size: Precision :: Absent ,
618619 } ,
619620 // column 2: right.id (Int32, file column from t2) - right partition 1: ids [1,2]
@@ -1252,7 +1253,7 @@ mod test {
12521253 DATE_2025_03_01 ,
12531254 ) ) ) ,
12541255 sum_value: Precision :: Absent ,
1255- distinct_count: Precision :: Inexact ( 1 ) ,
1256+ distinct_count: Precision :: Inexact ( 2 ) ,
12561257 byte_size: Precision :: Exact ( 8 ) ,
12571258 } ,
12581259 ColumnStatistics :: new_unknown( ) , // window column
@@ -1280,7 +1281,7 @@ mod test {
12801281 DATE_2025_03_03 ,
12811282 ) ) ) ,
12821283 sum_value: Precision :: Absent ,
1283- distinct_count: Precision :: Inexact ( 1 ) ,
1284+ distinct_count: Precision :: Inexact ( 2 ) ,
12841285 byte_size: Precision :: Exact ( 8 ) ,
12851286 } ,
12861287 ColumnStatistics :: new_unknown( ) , // window column
@@ -1417,8 +1418,7 @@ mod test {
14171418 byte_size: Precision :: Exact ( 16 ) ,
14181419 } ,
14191420 // Left date column: all partitions (2025-03-01..2025-03-04)
1420- // NDV is Inexact(1) because each Hive partition has exactly 1 distinct date value,
1421- // and merging takes max as a conservative lower bound
1421+ // NDV is Inexact(4) derived from the date range via interval analysis
14221422 ColumnStatistics {
14231423 null_count: Precision :: Exact ( 0 ) ,
14241424 max_value: Precision :: Exact ( ScalarValue :: Date32 ( Some (
@@ -1428,7 +1428,7 @@ mod test {
14281428 DATE_2025_03_01 ,
14291429 ) ) ) ,
14301430 sum_value: Precision :: Absent ,
1431- distinct_count: Precision :: Inexact ( 1 ) ,
1431+ distinct_count: Precision :: Inexact ( 4 ) ,
14321432 byte_size: Precision :: Exact ( 16 ) ,
14331433 } ,
14341434 // Right id column: partition 0 only (id 3..4)
@@ -1441,7 +1441,7 @@ mod test {
14411441 byte_size: Precision :: Exact ( 8 ) ,
14421442 } ,
14431443 // Right date column: partition 0 only (2025-03-01..2025-03-02)
1444- // NDV is Inexact(1) from the single Hive partition's date value
1444+ // NDV is Inexact(2) derived from the date range via interval analysis
14451445 ColumnStatistics {
14461446 null_count: Precision :: Exact ( 0 ) ,
14471447 max_value: Precision :: Exact ( ScalarValue :: Date32 ( Some (
@@ -1451,7 +1451,7 @@ mod test {
14511451 DATE_2025_03_01 ,
14521452 ) ) ) ,
14531453 sum_value: Precision :: Absent ,
1454- distinct_count: Precision :: Inexact ( 1 ) ,
1454+ distinct_count: Precision :: Inexact ( 2 ) ,
14551455 byte_size: Precision :: Exact ( 8 ) ,
14561456 } ,
14571457 ] ,
@@ -1503,7 +1503,7 @@ mod test {
15031503 DATE_2025_03_01 ,
15041504 ) ) ) ,
15051505 sum_value: Precision :: Absent ,
1506- distinct_count: Precision :: Inexact ( 1 ) ,
1506+ distinct_count: Precision :: Inexact ( 2 ) ,
15071507 byte_size: Precision :: Exact ( 8 ) ,
15081508 } ,
15091509 // Right id column: partition 0 only (id 3..4)
@@ -1525,7 +1525,7 @@ mod test {
15251525 DATE_2025_03_01 ,
15261526 ) ) ) ,
15271527 sum_value: Precision :: Absent ,
1528- distinct_count: Precision :: Inexact ( 1 ) ,
1528+ distinct_count: Precision :: Inexact ( 2 ) ,
15291529 byte_size: Precision :: Exact ( 8 ) ,
15301530 } ,
15311531 ] ,
@@ -1577,7 +1577,7 @@ mod test {
15771577 DATE_2025_03_01 ,
15781578 ) ) ) ,
15791579 sum_value: Precision :: Absent ,
1580- distinct_count: Precision :: Inexact ( 1 ) ,
1580+ distinct_count: Precision :: Inexact ( 4 ) ,
15811581 byte_size: Precision :: Exact ( 16 ) ,
15821582 } ,
15831583 // Right id column: all partitions (id 1..4)
@@ -1599,7 +1599,7 @@ mod test {
15991599 DATE_2025_03_01 ,
16001600 ) ) ) ,
16011601 sum_value: Precision :: Absent ,
1602- distinct_count: Precision :: Inexact ( 1 ) ,
1602+ distinct_count: Precision :: Inexact ( 4 ) ,
16031603 byte_size: Precision :: Exact ( 16 ) ,
16041604 } ,
16051605 ] ,
0 commit comments