-
Notifications
You must be signed in to change notification settings - Fork 821
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
Expose page encoding ColumnChunkMetadata
#1322
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
0191acf
init
shanisolomon 475a8b1
replaced test file
shanisolomon 2351e45
init
shanisolomon 1293359
merge
shanisolomon f654186
thrift conversion
shanisolomon 1794c20
refactor
shanisolomon 358f464
changes
shanisolomon e4a7b13
tests
shanisolomon 14a8828
merge
shanisolomon 9db23f8
clippy
shanisolomon File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,6 +39,7 @@ use parquet_format::{ColumnChunk, ColumnMetaData, RowGroup}; | |
|
||
use crate::basic::{ColumnOrder, Compression, Encoding, Type}; | ||
use crate::errors::{ParquetError, Result}; | ||
use crate::file::page_encoding_stats::{self, PageEncodingStats}; | ||
use crate::file::statistics::{self, Statistics}; | ||
use crate::schema::types::{ | ||
ColumnDescPtr, ColumnDescriptor, ColumnPath, SchemaDescPtr, SchemaDescriptor, | ||
|
@@ -349,6 +350,7 @@ pub struct ColumnChunkMetaData { | |
index_page_offset: Option<i64>, | ||
dictionary_page_offset: Option<i64>, | ||
statistics: Option<Statistics>, | ||
encoding_stats: Option<Vec<PageEncodingStats>>, | ||
bloom_filter_offset: Option<i64>, | ||
offset_index_offset: Option<i64>, | ||
offset_index_length: Option<i32>, | ||
|
@@ -467,6 +469,17 @@ impl ColumnChunkMetaData { | |
self.statistics.as_ref() | ||
} | ||
|
||
/// Returns `true` if this column chunk contains page encoding stats, `false` otherwise. | ||
pub fn has_page_encoding_stats(&self) -> bool { | ||
self.encoding_stats.is_some() | ||
} | ||
|
||
/// Returns the offset for the page encoding stats, | ||
/// or `None` if no page encoding stats are available. | ||
pub fn page_encoding_stats(&self) -> Option<&Vec<PageEncodingStats>> { | ||
self.encoding_stats.as_ref() | ||
} | ||
|
||
/// Returns `true` if this column chunk contains a bloom filter offset, `false` otherwise. | ||
pub fn has_bloom_filter(&self) -> bool { | ||
self.bloom_filter_offset.is_some() | ||
|
@@ -528,11 +541,16 @@ impl ColumnChunkMetaData { | |
let index_page_offset = col_metadata.index_page_offset; | ||
let dictionary_page_offset = col_metadata.dictionary_page_offset; | ||
let statistics = statistics::from_thrift(column_type, col_metadata.statistics); | ||
let encoding_stats = col_metadata | ||
.encoding_stats | ||
.as_ref() | ||
.map(|vec| vec.iter().map(page_encoding_stats::from_thrift).collect()); | ||
let bloom_filter_offset = col_metadata.bloom_filter_offset; | ||
let offset_index_offset = cc.offset_index_offset; | ||
let offset_index_length = cc.offset_index_length; | ||
let column_index_offset = cc.column_index_offset; | ||
let column_index_length = cc.column_index_length; | ||
|
||
let result = ColumnChunkMetaData { | ||
column_type, | ||
column_path, | ||
|
@@ -548,6 +566,7 @@ impl ColumnChunkMetaData { | |
index_page_offset, | ||
dictionary_page_offset, | ||
statistics, | ||
encoding_stats, | ||
bloom_filter_offset, | ||
offset_index_offset, | ||
offset_index_length, | ||
|
@@ -572,7 +591,10 @@ impl ColumnChunkMetaData { | |
index_page_offset: self.index_page_offset, | ||
dictionary_page_offset: self.dictionary_page_offset, | ||
statistics: statistics::to_thrift(self.statistics.as_ref()), | ||
encoding_stats: None, | ||
encoding_stats: self | ||
.encoding_stats | ||
.as_ref() | ||
.map(|vec| vec.iter().map(page_encoding_stats::to_thrift).collect()), | ||
bloom_filter_offset: self.bloom_filter_offset, | ||
}; | ||
|
||
|
@@ -604,6 +626,7 @@ pub struct ColumnChunkMetaDataBuilder { | |
index_page_offset: Option<i64>, | ||
dictionary_page_offset: Option<i64>, | ||
statistics: Option<Statistics>, | ||
encoding_stats: Option<Vec<PageEncodingStats>>, | ||
bloom_filter_offset: Option<i64>, | ||
offset_index_offset: Option<i64>, | ||
offset_index_length: Option<i32>, | ||
|
@@ -627,6 +650,7 @@ impl ColumnChunkMetaDataBuilder { | |
index_page_offset: None, | ||
dictionary_page_offset: None, | ||
statistics: None, | ||
encoding_stats: None, | ||
bloom_filter_offset: None, | ||
offset_index_offset: None, | ||
offset_index_length: None, | ||
|
@@ -701,6 +725,12 @@ impl ColumnChunkMetaDataBuilder { | |
self | ||
} | ||
|
||
/// Sets page encoding stats for this column chunk. | ||
pub fn set_page_encoding_stats(mut self, value: Vec<PageEncodingStats>) -> Self { | ||
self.encoding_stats = Some(value); | ||
self | ||
} | ||
|
||
/// Sets optional bloom filter offset in bytes. | ||
pub fn set_bloom_filter_offset(mut self, value: Option<i64>) -> Self { | ||
self.bloom_filter_offset = value; | ||
|
@@ -748,6 +778,7 @@ impl ColumnChunkMetaDataBuilder { | |
index_page_offset: self.index_page_offset, | ||
dictionary_page_offset: self.dictionary_page_offset, | ||
statistics: self.statistics, | ||
encoding_stats: self.encoding_stats, | ||
bloom_filter_offset: self.bloom_filter_offset, | ||
offset_index_offset: self.offset_index_offset, | ||
offset_index_length: self.offset_index_length, | ||
|
@@ -760,6 +791,7 @@ impl ColumnChunkMetaDataBuilder { | |
#[cfg(test)] | ||
mod tests { | ||
use super::*; | ||
use crate::basic::{Encoding, PageType}; | ||
|
||
#[test] | ||
fn test_row_group_metadata_thrift_conversion() { | ||
|
@@ -815,6 +847,18 @@ mod tests { | |
.set_total_uncompressed_size(3000) | ||
.set_data_page_offset(4000) | ||
.set_dictionary_page_offset(Some(5000)) | ||
.set_page_encoding_stats(vec![ | ||
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. 👍 |
||
PageEncodingStats { | ||
page_type: PageType::DATA_PAGE, | ||
encoding: Encoding::PLAIN, | ||
count: 3, | ||
}, | ||
PageEncodingStats { | ||
page_type: PageType::DATA_PAGE, | ||
encoding: Encoding::RLE, | ||
count: 5, | ||
}, | ||
]) | ||
.set_bloom_filter_offset(Some(6000)) | ||
.set_offset_index_offset(Some(7000)) | ||
.set_offset_index_length(Some(25)) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
// Licensed to the Apache Software Foundation (ASF) under one | ||
// or more contributor license agreements. See the NOTICE file | ||
// distributed with this work for additional information | ||
// regarding copyright ownership. The ASF licenses this file | ||
// to you under the Apache License, Version 2.0 (the | ||
// "License"); you may not use this file except in compliance | ||
// with the License. You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, | ||
// software distributed under the License is distributed on an | ||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
// KIND, either express or implied. See the License for the | ||
// specific language governing permissions and limitations | ||
// under the License. | ||
|
||
use crate::basic::{Encoding, PageType}; | ||
use parquet_format::{ | ||
Encoding as TEncoding, PageEncodingStats as TPageEncodingStats, PageType as TPageType, | ||
}; | ||
|
||
/// PageEncodingStats for a column chunk and data page. | ||
#[derive(Clone, Debug, PartialEq)] | ||
pub struct PageEncodingStats { | ||
/// the page type (data/dic/...) | ||
pub page_type: PageType, | ||
/// encoding of the page | ||
pub encoding: Encoding, | ||
/// number of pages of this type with this encoding | ||
pub count: i32, | ||
} | ||
|
||
/// Converts Thrift definition into `PageEncodingStats`. | ||
pub fn from_thrift(thrift_encoding_stats: &TPageEncodingStats) -> PageEncodingStats { | ||
let page_type = PageType::from(thrift_encoding_stats.page_type); | ||
let encoding = Encoding::from(thrift_encoding_stats.encoding); | ||
let count = thrift_encoding_stats.count; | ||
|
||
PageEncodingStats { | ||
page_type, | ||
encoding, | ||
count, | ||
} | ||
} | ||
|
||
/// Converts `PageEncodingStats` into Thrift definition. | ||
pub fn to_thrift(encoding_stats: &PageEncodingStats) -> TPageEncodingStats { | ||
let page_type = TPageType::from(encoding_stats.page_type); | ||
let encoding = TEncoding::from(encoding_stats.encoding); | ||
let count = encoding_stats.count; | ||
|
||
TPageEncodingStats { | ||
page_type, | ||
encoding, | ||
count, | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use super::*; | ||
use crate::basic::{Encoding, PageType}; | ||
|
||
#[test] | ||
fn test_page_encoding_stats_from_thrift() { | ||
let stats = PageEncodingStats { | ||
page_type: PageType::DATA_PAGE, | ||
encoding: Encoding::PLAIN, | ||
count: 1, | ||
}; | ||
|
||
assert_eq!(from_thrift(&to_thrift(&stats)), stats); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this method is redundant with the
page_encoding_stats
as I think most of the time any client code would process page_encoding_stats they would likely use code like:However, I see it is consistent with the methods of this file (and I didn't call this out in earlier PRs 😅 )
On the other hand, we haven't released the other methods (like
has_bloom_filter
so it isn't too late to remove them)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I introduce those methods in order to be consistent with the other
has_
methods for optional values in the metadata. Would you like me to remove all?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here is my proposal:
ColumnChunkMetadata
#1332