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 20 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
109 changes: 74 additions & 35 deletions parquet/src/arrow/arrow_reader/statistics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ macro_rules! make_stats_iterator {
let next = self.iter.next();
next.map(|x| {
x.and_then(|stats| match stats {
$parquet_statistics_type(s) if stats.has_min_max_set() => Some(s.$func()),
$parquet_statistics_type(s) => s.$func(),
_ => None,
})
})
Expand All @@ -131,45 +131,85 @@ macro_rules! make_stats_iterator {

make_stats_iterator!(
MinBooleanStatsIterator,
min,
min_opt,
ParquetStatistics::Boolean,
bool
);
make_stats_iterator!(
MaxBooleanStatsIterator,
max,
max_opt,
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_opt,
ParquetStatistics::Int32,
i32
);
make_stats_iterator!(
MaxInt32StatsIterator,
max_opt,
ParquetStatistics::Int32,
i32
);
make_stats_iterator!(
MinInt64StatsIterator,
min_opt,
ParquetStatistics::Int64,
i64
);
make_stats_iterator!(
MaxInt64StatsIterator,
max_opt,
ParquetStatistics::Int64,
i64
);
make_stats_iterator!(
MinFloatStatsIterator,
min_opt,
ParquetStatistics::Float,
f32
);
make_stats_iterator!(
MaxFloatStatsIterator,
max_opt,
ParquetStatistics::Float,
f32
);
make_stats_iterator!(
MinDoubleStatsIterator,
min_opt,
ParquetStatistics::Double,
f64
);
make_stats_iterator!(
MaxDoubleStatsIterator,
max_opt,
ParquetStatistics::Double,
f64
);
make_stats_iterator!(
MinByteArrayStatsIterator,
min_bytes,
min_bytes_opt,
ParquetStatistics::ByteArray,
[u8]
);
make_stats_iterator!(
MaxByteArrayStatsIterator,
max_bytes,
max_bytes_opt,
ParquetStatistics::ByteArray,
[u8]
);
make_stats_iterator!(
MinFixedLenByteArrayStatsIterator,
min_bytes,
min_bytes_opt,
ParquetStatistics::FixedLenByteArray,
[u8]
);
make_stats_iterator!(
MaxFixedLenByteArrayStatsIterator,
max_bytes,
max_bytes_opt,
ParquetStatistics::FixedLenByteArray,
[u8]
);
Expand Down Expand Up @@ -218,19 +258,18 @@ macro_rules! make_decimal_stats_iterator {
fn next(&mut self) -> Option<Self::Item> {
let next = self.iter.next();
next.map(|x| {
x.and_then(|stats| {
if !stats.has_min_max_set() {
return None;
x.and_then(|stats| match stats {
ParquetStatistics::Int32(s) => {
s.$func().map(|x| $stat_value_type::from(*x))
}
match stats {
ParquetStatistics::Int32(s) => Some($stat_value_type::from(*s.$func())),
ParquetStatistics::Int64(s) => Some($stat_value_type::from(*s.$func())),
ParquetStatistics::ByteArray(s) => Some($convert_func(s.$bytes_func())),
ParquetStatistics::FixedLenByteArray(s) => {
Some($convert_func(s.$bytes_func()))
}
_ => None,
ParquetStatistics::Int64(s) => {
s.$func().map(|x| $stat_value_type::from(*x))
}
ParquetStatistics::ByteArray(s) => s.$bytes_func().map($convert_func),
ParquetStatistics::FixedLenByteArray(s) => {
s.$bytes_func().map($convert_func)
}
_ => None,
})
})
}
Expand All @@ -244,29 +283,29 @@ macro_rules! make_decimal_stats_iterator {

make_decimal_stats_iterator!(
MinDecimal128StatsIterator,
min,
min_bytes,
min_opt,
min_bytes_opt,
i128,
from_bytes_to_i128
);
make_decimal_stats_iterator!(
MaxDecimal128StatsIterator,
max,
max_bytes,
max_opt,
max_bytes_opt,
i128,
from_bytes_to_i128
);
make_decimal_stats_iterator!(
MinDecimal256StatsIterator,
min,
min_bytes,
min_opt,
min_bytes_opt,
i256,
from_bytes_to_i256
);
make_decimal_stats_iterator!(
MaxDecimal256StatsIterator,
max,
max_bytes,
max_opt,
max_bytes_opt,
i256,
from_bytes_to_i256
);
Expand Down Expand Up @@ -1347,7 +1386,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_opt()));
Ok(UInt64Array::from_iter(null_counts))
}

Expand Down
34 changes: 23 additions & 11 deletions parquet/src/arrow/arrow_writer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2541,10 +2541,16 @@ mod tests {
row_offset += column.num_values() as usize;

let stats = column.statistics().unwrap();
assert!(stats.has_min_max_set());
assert!(stats._internal_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_opt().unwrap() as u32,
*src_slice.iter().min().unwrap()
);
assert_eq!(
*stats.max_opt().unwrap() as u32,
*src_slice.iter().max().unwrap()
);
} else {
panic!("Statistics::Int32 missing")
}
Expand Down Expand Up @@ -2582,10 +2588,16 @@ mod tests {
row_offset += column.num_values() as usize;

let stats = column.statistics().unwrap();
assert!(stats.has_min_max_set());
assert!(stats._internal_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_opt().unwrap() as u64,
*src_slice.iter().min().unwrap()
);
assert_eq!(
*stats.max_opt().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_opt(), 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_opt().unwrap();
let max = byte_array_stats.max_opt().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_opt().unwrap();
let max = byte_array_stats.max_opt().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