Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: use epoch instead of ce for date stats #1672

Merged
merged 5 commits into from
Sep 27, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 4 additions & 8 deletions rust/src/writer/stats.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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, .. })) => {
Expand Down Expand Up @@ -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),
Expand Down
Loading