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

feat: Add support for Timestamp data types in data page statistics. #11123

Merged
Show file tree
Hide file tree
Changes from 1 commit
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
30 changes: 30 additions & 0 deletions datafusion/core/src/datasource/physical_plan/parquet/statistics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -713,6 +713,36 @@ macro_rules! get_data_page_statistics {
)),
Some(DataType::Float32) => Ok(Arc::new(Float32Array::from_iter([<$stat_type_prefix Float32DataPageStatsIterator>]::new($iterator).flatten()))),
Some(DataType::Float64) => Ok(Arc::new(Float64Array::from_iter([<$stat_type_prefix Float64DataPageStatsIterator>]::new($iterator).flatten()))),
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Should this repeated code be extracted? I assume it would need to be put into a macro?

Copy link
Contributor

Choose a reason for hiding this comment

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

Which repeated code do you mean?

If you wnated to more fully macroize this table and avoid repetition that sounds like a great idea to me (though perhaps as a follow on PR)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The four lines in the match unit expression are exactly the same in both macros.

Some(DataType::Timestamp(unit, timezone)) => {
let iter = [<$stat_type_prefix Int64DataPageStatsIterator>]::new($iterator).flatten();

Ok(match unit {
TimeUnit::Second => {
Arc::new(match timezone {
Some(tz) => TimestampSecondArray::from_iter(iter).with_timezone(tz.clone()),
Copy link
Contributor

Choose a reason for hiding this comment

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

Not tested, but perhaps with_timezone_opt could reduce some the repetitiveness of the code.

Copy link
Contributor

Choose a reason for hiding this comment

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

that is a great suggestion

None => TimestampSecondArray::from_iter(iter),
})
}
TimeUnit::Millisecond => {
Arc::new(match timezone {
Some(tz) => TimestampMillisecondArray::from_iter(iter).with_timezone(tz.clone()),
None => TimestampMillisecondArray::from_iter(iter),
})
}
TimeUnit::Microsecond => {
Arc::new(match timezone {
Some(tz) => TimestampMicrosecondArray::from_iter(iter).with_timezone(tz.clone()),
None => TimestampMicrosecondArray::from_iter(iter),
})
}
TimeUnit::Nanosecond => {
Arc::new(match timezone {
Some(tz) => TimestampNanosecondArray::from_iter(iter).with_timezone(tz.clone()),
None => TimestampNanosecondArray::from_iter(iter),
})
}
})
},
_ => unimplemented!()
}
}
Expand Down
32 changes: 16 additions & 16 deletions datafusion/core/tests/parquet/arrow_statistics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -747,7 +747,7 @@ async fn test_timestamp() {
// row counts are [5, 5, 5, 5]
expected_row_counts: Some(UInt64Array::from(vec![5, 5, 5, 5])),
column_name: "nanos",
check: Check::RowGroup,
check: Check::Both,
}
.run();

Expand Down Expand Up @@ -776,7 +776,7 @@ async fn test_timestamp() {
// row counts are [5, 5, 5, 5]
expected_row_counts: Some(UInt64Array::from(vec![5, 5, 5, 5])),
column_name: "nanos_timezoned",
check: Check::RowGroup,
check: Check::Both,
}
.run();

Expand All @@ -798,7 +798,7 @@ async fn test_timestamp() {
expected_null_counts: UInt64Array::from(vec![1, 1, 1, 1]),
expected_row_counts: Some(UInt64Array::from(vec![5, 5, 5, 5])),
column_name: "micros",
check: Check::RowGroup,
check: Check::Both,
}
.run();

Expand Down Expand Up @@ -827,7 +827,7 @@ async fn test_timestamp() {
// row counts are [5, 5, 5, 5]
expected_row_counts: Some(UInt64Array::from(vec![5, 5, 5, 5])),
column_name: "micros_timezoned",
check: Check::RowGroup,
check: Check::Both,
}
.run();

Expand All @@ -849,7 +849,7 @@ async fn test_timestamp() {
expected_null_counts: UInt64Array::from(vec![1, 1, 1, 1]),
expected_row_counts: Some(UInt64Array::from(vec![5, 5, 5, 5])),
column_name: "millis",
check: Check::RowGroup,
check: Check::Both,
}
.run();

Expand Down Expand Up @@ -878,7 +878,7 @@ async fn test_timestamp() {
// row counts are [5, 5, 5, 5]
expected_row_counts: Some(UInt64Array::from(vec![5, 5, 5, 5])),
column_name: "millis_timezoned",
check: Check::RowGroup,
check: Check::Both,
}
.run();

Expand All @@ -900,7 +900,7 @@ async fn test_timestamp() {
expected_null_counts: UInt64Array::from(vec![1, 1, 1, 1]),
expected_row_counts: Some(UInt64Array::from(vec![5, 5, 5, 5])),
column_name: "seconds",
check: Check::RowGroup,
check: Check::Both,
}
.run();

Expand Down Expand Up @@ -929,7 +929,7 @@ async fn test_timestamp() {
// row counts are [5, 5, 5, 5]
expected_row_counts: Some(UInt64Array::from(vec![5, 5, 5, 5])),
column_name: "seconds_timezoned",
check: Check::RowGroup,
check: Check::Both,
}
.run();
}
Expand Down Expand Up @@ -975,7 +975,7 @@ async fn test_timestamp_diff_rg_sizes() {
// row counts are [8, 8, 4]
expected_row_counts: Some(UInt64Array::from(vec![8, 8, 4])),
column_name: "nanos",
check: Check::RowGroup,
check: Check::Both,
}
.run();

Expand All @@ -1002,7 +1002,7 @@ async fn test_timestamp_diff_rg_sizes() {
// row counts are [8, 8, 4]
expected_row_counts: Some(UInt64Array::from(vec![8, 8, 4])),
column_name: "nanos_timezoned",
check: Check::RowGroup,
check: Check::Both,
}
.run();

Expand All @@ -1022,7 +1022,7 @@ async fn test_timestamp_diff_rg_sizes() {
expected_null_counts: UInt64Array::from(vec![1, 2, 1]),
expected_row_counts: Some(UInt64Array::from(vec![8, 8, 4])),
column_name: "micros",
check: Check::RowGroup,
check: Check::Both,
}
.run();

Expand All @@ -1049,7 +1049,7 @@ async fn test_timestamp_diff_rg_sizes() {
// row counts are [8, 8, 4]
expected_row_counts: Some(UInt64Array::from(vec![8, 8, 4])),
column_name: "micros_timezoned",
check: Check::RowGroup,
check: Check::Both,
}
.run();

Expand All @@ -1069,7 +1069,7 @@ async fn test_timestamp_diff_rg_sizes() {
expected_null_counts: UInt64Array::from(vec![1, 2, 1]),
expected_row_counts: Some(UInt64Array::from(vec![8, 8, 4])),
column_name: "millis",
check: Check::RowGroup,
check: Check::Both,
}
.run();

Expand All @@ -1096,7 +1096,7 @@ async fn test_timestamp_diff_rg_sizes() {
// row counts are [8, 8, 4]
expected_row_counts: Some(UInt64Array::from(vec![8, 8, 4])),
column_name: "millis_timezoned",
check: Check::RowGroup,
check: Check::Both,
}
.run();

Expand All @@ -1116,7 +1116,7 @@ async fn test_timestamp_diff_rg_sizes() {
expected_null_counts: UInt64Array::from(vec![1, 2, 1]),
expected_row_counts: Some(UInt64Array::from(vec![8, 8, 4])),
column_name: "seconds",
check: Check::RowGroup,
check: Check::Both,
}
.run();

Expand All @@ -1143,7 +1143,7 @@ async fn test_timestamp_diff_rg_sizes() {
// row counts are [8, 8, 4]
expected_row_counts: Some(UInt64Array::from(vec![8, 8, 4])),
column_name: "seconds_timezoned",
check: Check::RowGroup,
check: Check::Both,
}
.run();
}
Expand Down
Loading