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

parquet Statistics - deprecate has_* APIs and add _opt functions that return Option<T> #6216

Merged
merged 24 commits into from
Aug 15, 2024
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
fd2ac15
update public api Statistics::min to return an option.
Michael-J-Ward Aug 9, 2024
18b467b
update public api Statistics::max to return an option.
Michael-J-Ward Aug 9, 2024
7ffac1a
cargo fmt
Michael-J-Ward Aug 9, 2024
87c375a
remove Statistics::has_min_max_set from the public api
Michael-J-Ward Aug 9, 2024
6950994
update impl HeapSize for ValueStatistics to use new min and max api
Michael-J-Ward Aug 9, 2024
c65a773
migrate all tests to new Statistics min and max api
Michael-J-Ward Aug 9, 2024
89ea21d
make Statistics::null_count return Option<u64>
Michael-J-Ward Aug 9, 2024
f2785f8
update expected metadata memory size tests
Michael-J-Ward Aug 9, 2024
9a4921f
add TODO question on is_min_max_backwards_compatible
Michael-J-Ward Aug 9, 2024
7e082a7
Apply suggestions from code review
Michael-J-Ward Aug 13, 2024
ddd8498
update ValueStatistics::max docs
Michael-J-Ward Aug 13, 2024
e92321b
rename new optional ValueStatistics::max to max_opt
Michael-J-Ward Aug 13, 2024
e4db777
rename new optional ValueStatistics::min to min_opt
Michael-J-Ward Aug 13, 2024
bd83a38
add Statistics:{min,max}_bytes_opt
Michael-J-Ward Aug 13, 2024
4e2909b
update make_stats_iterator macro to use *_opt methods
Michael-J-Ward Aug 14, 2024
2f3e21e
deprecate non *_opt Statistics and ValueStatistics methods
Michael-J-Ward Aug 14, 2024
050ba89
remove stale TODO comments
Michael-J-Ward Aug 14, 2024
fc0ed20
remove has_min_max_set check from make_decimal_stats_iterator
Michael-J-Ward Aug 14, 2024
2366942
deprecate has_min_max_set
Michael-J-Ward Aug 14, 2024
82b40b8
switch to null_count_opt and reintroduce deprecated null_count and ha…
Michael-J-Ward Aug 14, 2024
3efc631
remove redundant test assertions of stats._internal_has_min_max_set
Michael-J-Ward Aug 14, 2024
a23cf8b
replace negated test assertions of stats._internal_has_mix_max_set wi…
Michael-J-Ward Aug 14, 2024
7d4e650
Revert changes to parquet writing, update comments
alamb Aug 15, 2024
48a35d3
Merge remote-tracking branch 'apache/master' into parquet-has-min-max
alamb Aug 15, 2024
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
70 changes: 55 additions & 15 deletions parquet/src/arrow/arrow_reader/statistics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,24 +131,64 @@ macro_rules! make_stats_iterator {

make_stats_iterator!(
MinBooleanStatsIterator,
min,
min_unchecked,
ParquetStatistics::Boolean,
bool
);
make_stats_iterator!(
MaxBooleanStatsIterator,
max,
max_unchecked,
ParquetStatistics::Boolean,
bool
);
make_stats_iterator!(MinInt32StatsIterator, min, ParquetStatistics::Int32, i32);
make_stats_iterator!(MaxInt32StatsIterator, max, ParquetStatistics::Int32, i32);
make_stats_iterator!(MinInt64StatsIterator, min, ParquetStatistics::Int64, i64);
make_stats_iterator!(MaxInt64StatsIterator, max, ParquetStatistics::Int64, i64);
make_stats_iterator!(MinFloatStatsIterator, min, ParquetStatistics::Float, f32);
make_stats_iterator!(MaxFloatStatsIterator, max, ParquetStatistics::Float, f32);
make_stats_iterator!(MinDoubleStatsIterator, min, ParquetStatistics::Double, f64);
make_stats_iterator!(MaxDoubleStatsIterator, max, ParquetStatistics::Double, f64);
make_stats_iterator!(
MinInt32StatsIterator,
min_unchecked,
ParquetStatistics::Int32,
i32
);
make_stats_iterator!(
MaxInt32StatsIterator,
max_unchecked,
ParquetStatistics::Int32,
i32
);
make_stats_iterator!(
MinInt64StatsIterator,
min_unchecked,
ParquetStatistics::Int64,
i64
);
make_stats_iterator!(
MaxInt64StatsIterator,
max_unchecked,
ParquetStatistics::Int64,
i64
);
make_stats_iterator!(
MinFloatStatsIterator,
min_unchecked,
ParquetStatistics::Float,
f32
);
make_stats_iterator!(
MaxFloatStatsIterator,
max_unchecked,
ParquetStatistics::Float,
f32
);
make_stats_iterator!(
MinDoubleStatsIterator,
min_unchecked,
ParquetStatistics::Double,
f64
);
make_stats_iterator!(
MaxDoubleStatsIterator,
max_unchecked,
ParquetStatistics::Double,
f64
);
make_stats_iterator!(
MinByteArrayStatsIterator,
min_bytes,
Michael-J-Ward marked this conversation as resolved.
Show resolved Hide resolved
Expand Down Expand Up @@ -244,28 +284,28 @@ macro_rules! make_decimal_stats_iterator {

make_decimal_stats_iterator!(
MinDecimal128StatsIterator,
min,
min_unchecked,
min_bytes,
i128,
from_bytes_to_i128
);
make_decimal_stats_iterator!(
MaxDecimal128StatsIterator,
max,
max_unchecked,
max_bytes,
i128,
from_bytes_to_i128
);
make_decimal_stats_iterator!(
MinDecimal256StatsIterator,
min,
min_unchecked,
min_bytes,
i256,
from_bytes_to_i256
);
make_decimal_stats_iterator!(
MaxDecimal256StatsIterator,
max,
max_unchecked,
max_bytes,
i256,
from_bytes_to_i256
Expand Down Expand Up @@ -1347,7 +1387,7 @@ impl<'a> StatisticsConverter<'a> {
let null_counts = metadatas
.into_iter()
.map(|x| x.column(parquet_index).statistics())
.map(|s| s.map(|s| s.null_count()));
.map(|s| s.and_then(|s| s.null_count()));
Ok(UInt64Array::from_iter(null_counts))
}

Expand Down
30 changes: 21 additions & 9 deletions parquet/src/arrow/arrow_writer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2543,8 +2543,14 @@ mod tests {
let stats = column.statistics().unwrap();
assert!(stats.has_min_max_set());
if let Statistics::Int32(stats) = stats {
assert_eq!(*stats.min() as u32, *src_slice.iter().min().unwrap());
assert_eq!(*stats.max() as u32, *src_slice.iter().max().unwrap());
assert_eq!(
*stats.min().unwrap() as u32,
*src_slice.iter().min().unwrap()
);
assert_eq!(
*stats.max().unwrap() as u32,
*src_slice.iter().max().unwrap()
);
} else {
panic!("Statistics::Int32 missing")
}
Expand Down Expand Up @@ -2584,8 +2590,14 @@ mod tests {
let stats = column.statistics().unwrap();
assert!(stats.has_min_max_set());
if let Statistics::Int64(stats) = stats {
assert_eq!(*stats.min() as u64, *src_slice.iter().min().unwrap());
assert_eq!(*stats.max() as u64, *src_slice.iter().max().unwrap());
assert_eq!(
*stats.min().unwrap() as u64,
*src_slice.iter().min().unwrap()
);
assert_eq!(
*stats.max().unwrap() as u64,
*src_slice.iter().max().unwrap()
);
} else {
panic!("Statistics::Int64 missing")
}
Expand All @@ -2608,7 +2620,7 @@ mod tests {
assert_eq!(row_group.num_columns(), 1);
let column = row_group.column(0);
let stats = column.statistics().unwrap();
assert_eq!(stats.null_count(), 2);
assert_eq!(stats.null_count(), Some(2));
}
}

Expand Down Expand Up @@ -3069,8 +3081,8 @@ mod tests {

// Column chunk of column "a" should have chunk level statistics
if let Statistics::ByteArray(byte_array_stats) = a_col.statistics().unwrap() {
let min = byte_array_stats.min();
let max = byte_array_stats.max();
let min = byte_array_stats.min().unwrap();
let max = byte_array_stats.max().unwrap();

assert_eq!(min.as_bytes(), &[b'a']);
assert_eq!(max.as_bytes(), &[b'd']);
Expand Down Expand Up @@ -3141,8 +3153,8 @@ mod tests {

// Column chunk of column "a" should have chunk level statistics
if let Statistics::ByteArray(byte_array_stats) = a_col.statistics().unwrap() {
let min = byte_array_stats.min();
let max = byte_array_stats.max();
let min = byte_array_stats.min().unwrap();
let max = byte_array_stats.max().unwrap();

assert_eq!(min.as_bytes(), &[b'a']);
assert_eq!(max.as_bytes(), &[b'd']);
Expand Down
10 changes: 5 additions & 5 deletions parquet/src/column/page.rs
Original file line number Diff line number Diff line change
Expand Up @@ -370,15 +370,15 @@ mod tests {
encoding: Encoding::PLAIN,
def_level_encoding: Encoding::RLE,
rep_level_encoding: Encoding::RLE,
statistics: Some(Statistics::int32(Some(1), Some(2), None, 1, true)),
statistics: Some(Statistics::int32(Some(1), Some(2), None, Some(1), true)),
};
assert_eq!(data_page.page_type(), PageType::DATA_PAGE);
assert_eq!(data_page.buffer(), vec![0, 1, 2].as_slice());
assert_eq!(data_page.num_values(), 10);
assert_eq!(data_page.encoding(), Encoding::PLAIN);
assert_eq!(
data_page.statistics(),
Some(&Statistics::int32(Some(1), Some(2), None, 1, true))
Some(&Statistics::int32(Some(1), Some(2), None, Some(1), true))
);

let data_page_v2 = Page::DataPageV2 {
Expand All @@ -390,15 +390,15 @@ mod tests {
def_levels_byte_len: 30,
rep_levels_byte_len: 40,
is_compressed: false,
statistics: Some(Statistics::int32(Some(1), Some(2), None, 1, true)),
statistics: Some(Statistics::int32(Some(1), Some(2), None, Some(1), true)),
};
assert_eq!(data_page_v2.page_type(), PageType::DATA_PAGE_V2);
assert_eq!(data_page_v2.buffer(), vec![0, 1, 2].as_slice());
assert_eq!(data_page_v2.num_values(), 10);
assert_eq!(data_page_v2.encoding(), Encoding::PLAIN);
assert_eq!(
data_page_v2.statistics(),
Some(&Statistics::int32(Some(1), Some(2), None, 1, true))
Some(&Statistics::int32(Some(1), Some(2), None, Some(1), true))
);

let dict_page = Page::DictionaryPage {
Expand All @@ -422,7 +422,7 @@ mod tests {
encoding: Encoding::PLAIN,
def_level_encoding: Encoding::RLE,
rep_level_encoding: Encoding::RLE,
statistics: Some(Statistics::int32(Some(1), Some(2), None, 1, true)),
statistics: Some(Statistics::int32(Some(1), Some(2), None, Some(1), true)),
};

let cpage = CompressedPage::new(data_page, 5);
Expand Down
Loading
Loading