-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Extract Date32 parquet statistics as Date32Array rather than Int32Array
#10593
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
Changes from all commits
3530904
b451329
f13b5b7
aec4f27
43cf435
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -75,6 +75,12 @@ macro_rules! get_statistic { | |
| *scale, | ||
| )) | ||
| } | ||
| Some(DataType::Date32) => { | ||
| Some(ScalarValue::Date32(Some(*s.$func()))) | ||
| } | ||
| Some(DataType::Date64) => { | ||
| Some(ScalarValue::Date64(Some(i64::from(*s.$func()) * 24 * 60 * 60 * 1000))) | ||
| } | ||
| _ => Some(ScalarValue::Int32(Some(*s.$func()))), | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This seems to be the root cause of the bug, is it something that needs to be addressed in a different PR @alamb ? "catch-all" pattern matching branches are evil
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree it is likely what is masking all the bugs I am not sure if it is worth explicitly listing all the types out here to be honest 🤔 I am hoping in some future PR to revamp how these statistics are done entirely (basically match on the arrow target type in the outer loop rather than the inner loop) |
||
| } | ||
| } | ||
|
|
@@ -363,10 +369,12 @@ impl<'a> StatisticsConverter<'a> { | |
| #[cfg(test)] | ||
| mod test { | ||
| use super::*; | ||
| use arrow::compute::kernels::cast_utils::Parser; | ||
| use arrow::datatypes::{Date32Type, Date64Type}; | ||
| use arrow_array::{ | ||
| new_null_array, Array, BinaryArray, BooleanArray, Decimal128Array, Float32Array, | ||
| Float64Array, Int32Array, Int64Array, RecordBatch, StringArray, StructArray, | ||
| TimestampNanosecondArray, | ||
| new_null_array, Array, BinaryArray, BooleanArray, Date32Array, Date64Array, | ||
| Decimal128Array, Float32Array, Float64Array, Int32Array, Int64Array, RecordBatch, | ||
| StringArray, StructArray, TimestampNanosecondArray, | ||
| }; | ||
| use arrow_schema::{Field, SchemaRef}; | ||
| use bytes::Bytes; | ||
|
|
@@ -664,6 +672,68 @@ mod test { | |
| .run() | ||
| } | ||
|
|
||
| #[test] | ||
| fn roundtrip_date32() { | ||
| Test { | ||
| input: date32_array(vec![ | ||
| // row group 1 | ||
| Some("2021-01-01"), | ||
| None, | ||
| Some("2021-01-03"), | ||
| // row group 2 | ||
| Some("2021-01-01"), | ||
| Some("2021-01-05"), | ||
| None, | ||
| // row group 3 | ||
| None, | ||
| None, | ||
| None, | ||
| ]), | ||
| expected_min: date32_array(vec![ | ||
| Some("2021-01-01"), | ||
| Some("2021-01-01"), | ||
| None, | ||
| ]), | ||
| expected_max: date32_array(vec![ | ||
| Some("2021-01-03"), | ||
| Some("2021-01-05"), | ||
| None, | ||
| ]), | ||
| } | ||
| .run() | ||
| } | ||
|
|
||
| #[test] | ||
| fn roundtrip_date64() { | ||
| Test { | ||
| input: date64_array(vec![ | ||
| // row group 1 | ||
| Some("2021-01-01"), | ||
| None, | ||
| Some("2021-01-03"), | ||
| // row group 2 | ||
| Some("2021-01-01"), | ||
| Some("2021-01-05"), | ||
| None, | ||
| // row group 3 | ||
| None, | ||
| None, | ||
| None, | ||
| ]), | ||
| expected_min: date64_array(vec![ | ||
| Some("2021-01-01"), | ||
| Some("2021-01-01"), | ||
| None, | ||
| ]), | ||
| expected_max: date64_array(vec![ | ||
| Some("2021-01-03"), | ||
| Some("2021-01-05"), | ||
| None, | ||
| ]), | ||
| } | ||
| .run() | ||
| } | ||
|
|
||
| #[test] | ||
| fn struct_and_non_struct() { | ||
| // Ensures that statistics for an array that appears *after* a struct | ||
|
|
@@ -1069,4 +1139,24 @@ mod test { | |
| ]); | ||
| Arc::new(struct_array) | ||
| } | ||
|
|
||
| fn date32_array<'a>(input: impl IntoIterator<Item = Option<&'a str>>) -> ArrayRef { | ||
| let array = Date32Array::from( | ||
| input | ||
| .into_iter() | ||
| .map(|s| Date32Type::parse(s.unwrap_or_default())) | ||
| .collect::<Vec<_>>(), | ||
| ); | ||
| Arc::new(array) | ||
| } | ||
|
|
||
| fn date64_array<'a>(input: impl IntoIterator<Item = Option<&'a str>>) -> ArrayRef { | ||
| let array = Date64Array::from( | ||
| input | ||
| .into_iter() | ||
| .map(|s| Date64Type::parse(s.unwrap_or_default())) | ||
| .collect::<Vec<_>>(), | ||
| ); | ||
| Arc::new(array) | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.