From e1f966d25fc8dfe4cc3a954d86d0cb1fdda276a5 Mon Sep 17 00:00:00 2001 From: universalmind303 Date: Tue, 26 Sep 2023 20:32:02 -0500 Subject: [PATCH] fix: use epoch instead of ce for date stats --- rust/src/writer/stats.rs | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/rust/src/writer/stats.rs b/rust/src/writer/stats.rs index d96508d14f..1da199a6fb 100644 --- a/rust/src/writer/stats.rs +++ b/rust/src/writer/stats.rs @@ -147,12 +147,8 @@ impl StatsScalar { (Statistics::Boolean(v), _) => Ok(Self::Boolean(get_stat!(v))), // Int32 can be date, decimal, or just int32 (Statistics::Int32(v), Some(LogicalType::Date)) => { - let date = chrono::NaiveDate::from_num_days_from_ce_opt(get_stat!(v)).ok_or( - DeltaWriterError::StatsParsingFailed { - debug_value: v.to_string(), - logical_type: Some(LogicalType::Date), - }, - )?; + let epoch_start = chrono::NaiveDate::from_ymd_opt(1970, 1, 1).unwrap(); // creating from epoch should be infallible + let date = epoch_start + chrono::Duration::days(get_stat!(v) as i64); Ok(Self::Date(date)) } (Statistics::Int32(v), Some(LogicalType::Decimal { scale, .. })) => { @@ -540,9 +536,9 @@ mod tests { Value::from(12340.0), ), ( - simple_parquet_stat!(Statistics::Int32, 737821), + simple_parquet_stat!(Statistics::Int32, 10561), Some(LogicalType::Date), - Value::from("2021-01-31"), + Value::from("1998-12-01"), ), ( simple_parquet_stat!(Statistics::Int64, 1641040496789123456),