Skip to content
Merged
Show file tree
Hide file tree
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
42 changes: 35 additions & 7 deletions datafusion/core/src/datasource/physical_plan/parquet/statistics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@
use arrow::datatypes::i256;
use arrow::{array::ArrayRef, datatypes::DataType};
use arrow_array::{
new_null_array, BinaryArray, BooleanArray, Date32Array, Date64Array, Decimal128Array,
Decimal256Array, FixedSizeBinaryArray, Float16Array, Float32Array, Float64Array,
Int16Array, Int32Array, Int64Array, Int8Array, LargeBinaryArray, LargeStringArray,
StringArray, Time32MillisecondArray, Time32SecondArray, Time64MicrosecondArray,
Time64NanosecondArray, TimestampMicrosecondArray, TimestampMillisecondArray,
TimestampNanosecondArray, TimestampSecondArray, UInt16Array, UInt32Array,
UInt64Array, UInt8Array,
new_empty_array, new_null_array, BinaryArray, BooleanArray, Date32Array, Date64Array,
Decimal128Array, Decimal256Array, FixedSizeBinaryArray, Float16Array, Float32Array,
Float64Array, Int16Array, Int32Array, Int64Array, Int8Array, LargeBinaryArray,
LargeStringArray, StringArray, Time32MillisecondArray, Time32SecondArray,
Time64MicrosecondArray, Time64NanosecondArray, TimestampMicrosecondArray,
TimestampMillisecondArray, TimestampNanosecondArray, TimestampSecondArray,
UInt16Array, UInt32Array, UInt64Array, UInt8Array,
};
use arrow_schema::{Field, FieldRef, Schema, TimeUnit};
use datafusion_common::{internal_datafusion_err, internal_err, plan_err, Result};
Expand Down Expand Up @@ -873,6 +873,34 @@ macro_rules! get_data_page_statistics {
Decimal128Array::from_iter([<$stat_type_prefix Decimal128DataPageStatsIterator>]::new($iterator).flatten()).with_precision_and_scale(*precision, *scale)?)),
Some(DataType::Decimal256(precision, scale)) => Ok(Arc::new(
Decimal256Array::from_iter([<$stat_type_prefix Decimal256DataPageStatsIterator>]::new($iterator).flatten()).with_precision_and_scale(*precision, *scale)?)),
Some(DataType::Time32(unit)) => {
Ok(match unit {
TimeUnit::Second => Arc::new(Time32SecondArray::from_iter(
[<$stat_type_prefix Int32DataPageStatsIterator>]::new($iterator).flatten(),
)),
TimeUnit::Millisecond => Arc::new(Time32MillisecondArray::from_iter(
[<$stat_type_prefix Int32DataPageStatsIterator>]::new($iterator).flatten(),
)),
_ => {
// don't know how to extract statistics, so return an empty array
new_empty_array(&DataType::Time32(unit.clone()))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Technically speaking I think Time32 must be either Seconds or Milliseconds otherwise it is not a valid type.

https://docs.rs/arrow/latest/arrow/datatypes/enum.DataType.html#variant.Time32

However, the arrow-rs library doesn't encode this in the types so I think this is a reasonable behavior

}
})
}
Some(DataType::Time64(unit)) => {
Ok(match unit {
TimeUnit::Microsecond => Arc::new(Time64MicrosecondArray::from_iter(
[<$stat_type_prefix Int64DataPageStatsIterator>]::new($iterator).flatten(),
)),
TimeUnit::Nanosecond => Arc::new(Time64NanosecondArray::from_iter(
[<$stat_type_prefix Int64DataPageStatsIterator>]::new($iterator).flatten(),
)),
_ => {
// don't know how to extract statistics, so return an empty array
new_empty_array(&DataType::Time64(unit.clone()))
}
})
}
_ => unimplemented!()
}
}
Expand Down
8 changes: 4 additions & 4 deletions datafusion/core/tests/parquet/arrow_statistics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1204,7 +1204,7 @@ async fn test_time32_second_diff_rg_sizes() {
expected_null_counts: UInt64Array::from(vec![0, 0, 0, 0]), // Assuming 1 null per row group for simplicity
expected_row_counts: Some(UInt64Array::from(vec![4, 4, 4, 4])),
column_name: "second",
check: Check::RowGroup,
check: Check::Both,
}
.run();
}
Expand All @@ -1231,7 +1231,7 @@ async fn test_time32_millisecond_diff_rg_sizes() {
expected_null_counts: UInt64Array::from(vec![0, 0, 0, 0]), // Assuming 1 null per row group for simplicity
expected_row_counts: Some(UInt64Array::from(vec![4, 4, 4, 4])),
column_name: "millisecond",
check: Check::RowGroup,
check: Check::Both,
}
.run();
}
Expand Down Expand Up @@ -1264,7 +1264,7 @@ async fn test_time64_microsecond_diff_rg_sizes() {
expected_null_counts: UInt64Array::from(vec![0, 0, 0, 0]), // Assuming 1 null per row group for simplicity
expected_row_counts: Some(UInt64Array::from(vec![4, 4, 4, 4])),
column_name: "microsecond",
check: Check::RowGroup,
check: Check::Both,
}
.run();
}
Expand Down Expand Up @@ -1297,7 +1297,7 @@ async fn test_time64_nanosecond_diff_rg_sizes() {
expected_null_counts: UInt64Array::from(vec![0, 0, 0, 0]), // Assuming 1 null per row group for simplicity
expected_row_counts: Some(UInt64Array::from(vec![4, 4, 4, 4])),
column_name: "nanosecond",
check: Check::RowGroup,
check: Check::Both,
}
.run();
}
Expand Down