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

Expose bloom filter offset in ColumnChunkMetadata #1309

Merged
merged 6 commits into from
Feb 15, 2022
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
22 changes: 22 additions & 0 deletions parquet/src/file/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,7 @@ pub struct ColumnChunkMetaData {
index_page_offset: Option<i64>,
dictionary_page_offset: Option<i64>,
statistics: Option<Statistics>,
bloom_filter_offset: Option<i64>,
}

/// Represents common operations for a column chunk.
Expand Down Expand Up @@ -462,6 +463,16 @@ impl ColumnChunkMetaData {
self.statistics.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()
}

/// Returns the offset for the bloom filter.
pub fn bloom_filter_offset(&self) -> Option<i64> {
self.bloom_filter_offset
}

/// Method to convert from Thrift.
pub fn from_thrift(column_descr: ColumnDescPtr, cc: ColumnChunk) -> Result<Self> {
if cc.meta_data.is_none() {
Expand All @@ -485,6 +496,7 @@ 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 bloom_filter_offset = col_metadata.bloom_filter_offset;
let result = ColumnChunkMetaData {
column_type,
column_path,
Expand All @@ -500,6 +512,7 @@ impl ColumnChunkMetaData {
index_page_offset,
dictionary_page_offset,
statistics,
bloom_filter_offset,
};
Ok(result)
}
Expand Down Expand Up @@ -551,6 +564,7 @@ pub struct ColumnChunkMetaDataBuilder {
index_page_offset: Option<i64>,
dictionary_page_offset: Option<i64>,
statistics: Option<Statistics>,
bloom_filter_offset: Option<i64>,
}

impl ColumnChunkMetaDataBuilder {
Expand All @@ -569,6 +583,7 @@ impl ColumnChunkMetaDataBuilder {
index_page_offset: None,
dictionary_page_offset: None,
statistics: None,
bloom_filter_offset: None,
}
}

Expand Down Expand Up @@ -638,6 +653,12 @@ impl ColumnChunkMetaDataBuilder {
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;
self
}

/// Builds column chunk metadata.
pub fn build(self) -> Result<ColumnChunkMetaData> {
Ok(ColumnChunkMetaData {
Expand All @@ -655,6 +676,7 @@ impl ColumnChunkMetaDataBuilder {
index_page_offset: self.index_page_offset,
dictionary_page_offset: self.dictionary_page_offset,
statistics: self.statistics,
bloom_filter_offset: self.bloom_filter_offset,
})
}
}
Expand Down
13 changes: 13 additions & 0 deletions parquet/src/file/serialized_reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -760,6 +760,19 @@ mod tests {
);
}

#[test]
fn test_file_reader_optional_metadata() {
// file with optional metadata: bloom filters, encoding stats, column index and offset index.
let file = get_test_file("data_index_bloom_encoding_stats.parquet");
let file_reader = Arc::new(SerializedFileReader::new(file).unwrap());

let row_group_metadata = file_reader.metadata.row_group(0);
let col0_metadata = row_group_metadata.column(0);

// test optional bloom filter offset
assert_eq!(col0_metadata.bloom_filter_offset().unwrap(), 192);
}

#[test]
fn test_file_reader_filter_row_groups() -> Result<()> {
let test_file = get_test_file("alltypes_plain.parquet");
Expand Down
5 changes: 5 additions & 0 deletions parquet/src/schema/printer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,11 @@ fn print_column_chunk_metadata(
Some(stats) => stats.to_string(),
};
writeln!(out, "statistics: {}", statistics_str);
let bloom_filter_offset_str = match cc_metadata.bloom_filter_offset() {
None => "N/A".to_owned(),
Some(bfo) => bfo.to_string(),
};
writeln!(out, "bloom filter offset: {}", bloom_filter_offset_str);
writeln!(out);
}

Expand Down