-
Notifications
You must be signed in to change notification settings - Fork 796
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
Write Bloom filters between row groups instead of the end #5860
Merged
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
759767b
Add example script to write Parquet files with a Bloom filter
progval a417f01
Write Bloom filters between row groups instead of the end
progval 5daf96f
Merge branch 'master' into interleave-bloom
progval 6effa7f
Add WriterProperties::bloom_filter_position
progval f23759a
Mutate the right row group metadata
progval 83b475e
Add a test for Bloom Filters written at the end
progval 3f810b5
Update async writer accordingly
progval ad0c40e
Undo accidental commit
progval 74c40ee
Clippy
progval f237e8c
Apply suggestions from code review
progval d2a7ab8
Rewrite example with constants as parameters and fewer dependencies
progval b434eea
Merge branch 'master' into interleave-bloom
progval 942c6ab
rustfmt
progval e4a588d
Clippy
progval ed9e576
Fix MSRV
progval abd81ef
Merge remote-tracking branch 'apache/master' into interleave-bloom
alamb 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
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,131 @@ | ||
// 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 std::fs::File; | ||
use std::path::PathBuf; | ||
use std::sync::Arc; | ||
use std::time::{Duration, Instant}; | ||
|
||
use arrow::array::{StructArray, UInt64Builder}; | ||
use arrow::datatypes::DataType::UInt64; | ||
use arrow::datatypes::{Field, Schema}; | ||
use clap::{Parser, ValueEnum}; | ||
use parquet::arrow::ArrowWriter as ParquetWriter; | ||
use parquet::basic::Encoding; | ||
use parquet::errors::Result; | ||
use parquet::file::properties::{BloomFilterPosition, WriterProperties}; | ||
use sysinfo::{MemoryRefreshKind, Pid, ProcessRefreshKind, RefreshKind, System}; | ||
|
||
#[derive(ValueEnum, Clone)] | ||
enum BloomFilterPositionArg { | ||
End, | ||
AfterRowGroup, | ||
} | ||
|
||
#[derive(Parser)] | ||
#[command(version)] | ||
/// Writes sequences of integers, with a Bloom Filter, while logging timing and memory usage. | ||
struct Args { | ||
#[arg(long, default_value_t = 1000)] | ||
/// Number of batches to write | ||
iterations: u64, | ||
|
||
#[arg(long, default_value_t = 1000000)] | ||
/// Number of rows in each batch | ||
batch: u64, | ||
|
||
#[arg(long, value_enum, default_value_t=BloomFilterPositionArg::AfterRowGroup)] | ||
/// Where to write Bloom Filters | ||
bloom_filter_position: BloomFilterPositionArg, | ||
|
||
/// Path to the file to write | ||
path: PathBuf, | ||
} | ||
|
||
fn now() -> String { | ||
chrono::Local::now().format("%Y-%m-%d %H:%M:%S").to_string() | ||
} | ||
|
||
fn mem(system: &mut System) -> String { | ||
let pid = Pid::from(std::process::id() as usize); | ||
system.refresh_process_specifics(pid, ProcessRefreshKind::new().with_memory()); | ||
system | ||
.process(pid) | ||
.map(|proc| format!("{}MB", proc.memory() / 1_000_000)) | ||
.unwrap_or("N/A".to_string()) | ||
} | ||
|
||
fn main() -> Result<()> { | ||
let args = Args::parse(); | ||
|
||
let bloom_filter_position = match args.bloom_filter_position { | ||
BloomFilterPositionArg::End => BloomFilterPosition::End, | ||
BloomFilterPositionArg::AfterRowGroup => BloomFilterPosition::AfterRowGroup, | ||
}; | ||
|
||
let properties = WriterProperties::builder() | ||
.set_column_bloom_filter_enabled("id".into(), true) | ||
.set_column_encoding("id".into(), Encoding::DELTA_BINARY_PACKED) | ||
.set_bloom_filter_position(bloom_filter_position) | ||
.build(); | ||
let schema = Arc::new(Schema::new(vec![Field::new("id", UInt64, false)])); | ||
// Create parquet file that will be read. | ||
let file = File::create(args.path).unwrap(); | ||
let mut writer = ParquetWriter::try_new(file, schema.clone(), Some(properties))?; | ||
|
||
let mut system = | ||
System::new_with_specifics(RefreshKind::new().with_memory(MemoryRefreshKind::everything())); | ||
eprintln!( | ||
"{} Writing {} batches of {} rows. RSS = {}", | ||
now(), | ||
args.iterations, | ||
args.batch, | ||
mem(&mut system) | ||
); | ||
|
||
let mut array_builder = UInt64Builder::new(); | ||
let mut last_log = Instant::now(); | ||
for i in 0..args.iterations { | ||
if Instant::now() - last_log > Duration::new(10, 0) { | ||
last_log = Instant::now(); | ||
eprintln!( | ||
"{} Iteration {}/{}. RSS = {}", | ||
now(), | ||
i + 1, | ||
args.iterations, | ||
mem(&mut system) | ||
); | ||
} | ||
for j in 0..args.batch { | ||
array_builder.append_value(i + j); | ||
} | ||
writer.write( | ||
&StructArray::new( | ||
schema.fields().clone(), | ||
vec![Arc::new(array_builder.finish())], | ||
None, | ||
) | ||
.into(), | ||
)?; | ||
} | ||
writer.flush()?; | ||
writer.close()?; | ||
|
||
eprintln!("{} Done. RSS = {}", now(), mem(&mut system)); | ||
|
||
Ok(()) | ||
} |
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
Perhaps we could add some comments here explaining what this example is trying to show
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.
Done, along with a Clap argument parser: