-
Notifications
You must be signed in to change notification settings - Fork 1k
Arrow-Parquet SBBF coercion #8551
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
Open
mr-brobot
wants to merge
17
commits into
apache:main
Choose a base branch
from
mr-brobot:feat/parquet/arrow-sbbf
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
c9bbc44
feat(parquet): arrow sbbf
mr-brobot 15f131c
feat(parquet): sbbf benchmarks
mr-brobot 8e372d9
fix(parquet): arrow sbbf date64 support
mr-brobot 94056fa
refactor(parquet): simplify bloom filter tests
mr-brobot dcd6107
feat(parquet): arrow sbbf date type handling
mr-brobot 7e5cdc3
fix(parquet): arrow sbbf malformed input handling
mr-brobot 3ec2a94
test(parquet): arrow sbbf decimal256 coercion
mr-brobot 829dd52
fix(parquet): simplify sbbf benchmark
mr-brobot 094564c
fix(parquet): simplify sbbf decimal coercion
mr-brobot daea390
fix(parquet): sbbf doc reference
mr-brobot 0654b40
fix(parquet): sbbf benchmark noise threshold
mr-brobot ebbf94a
feat(parquet): add sbbf check benches
mr-brobot cbf6db2
fix(parquet): isolate decimal sbbf benches
mr-brobot 93a74b1
chore(parquet): reorder arrow sbbf tests
mr-brobot 981eaaa
fix(parquet): remove unnecessary arrow sbbf coercion
mr-brobot 3b70bf8
fix(parquet): simplify arrow sbbf coercion logic
mr-brobot 2aae14e
chore(parquet): reduce sbbf bench array size
mr-brobot 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 hidden or 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 hidden or 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,205 @@ | ||
// 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 arrow_array::{ArrayRef, Decimal128Array, Int32Array, Int8Array, RecordBatch}; | ||
use arrow_schema::{DataType, Field, Schema}; | ||
use criterion::*; | ||
use parquet::arrow::arrow_writer::ArrowWriter; | ||
use parquet::arrow::bloom_filter::ArrowSbbf; | ||
use parquet::bloom_filter::Sbbf; | ||
use parquet::file::properties::{ReaderProperties, WriterProperties}; | ||
use parquet::file::reader::{FileReader, SerializedFileReader}; | ||
use parquet::file::serialized_reader::ReadOptionsBuilder; | ||
use std::hint; | ||
use std::sync::Arc; | ||
use tempfile::tempfile; | ||
|
||
/// Helper function to create an Sbbf from an array for benchmarking | ||
/// | ||
/// Writes the given array to a Parquet file with bloom filters enabled, | ||
/// then reads it back and returns the bloom filter for the first column. | ||
fn setup_sbbf(array: ArrayRef, field: Field) -> Sbbf { | ||
let schema = Arc::new(Schema::new(vec![field.clone()])); | ||
let batch = RecordBatch::try_new(schema.clone(), vec![array]).unwrap(); | ||
|
||
// Write to parquet with bloom filter | ||
let mut file = tempfile().unwrap(); | ||
let props = WriterProperties::builder() | ||
.set_bloom_filter_enabled(true) | ||
.build(); | ||
let mut writer = ArrowWriter::try_new(&mut file, schema, Some(props)).unwrap(); | ||
writer.write(&batch).unwrap(); | ||
writer.close().unwrap(); | ||
|
||
// Read bloom filter back | ||
let options = ReadOptionsBuilder::new() | ||
.with_reader_properties( | ||
ReaderProperties::builder() | ||
.set_read_bloom_filter(true) | ||
.build(), | ||
) | ||
.build(); | ||
let reader = SerializedFileReader::new_with_options(file, options).unwrap(); | ||
let row_group_reader = reader.get_row_group(0).unwrap(); | ||
|
||
row_group_reader | ||
.get_column_bloom_filter(0) | ||
.expect("Bloom filter should exist") | ||
.clone() | ||
} | ||
|
||
fn bench_integer_types(c: &mut Criterion) { | ||
// Setup for Int8 benchmarks | ||
let test_val_i8 = 42i8; | ||
let int8_array = Arc::new(Int8Array::from(vec![test_val_i8; 1])) as ArrayRef; | ||
let int8_field = Field::new("col", DataType::Int8, false); | ||
let sbbf_int8 = setup_sbbf(int8_array, int8_field); | ||
let arrow_sbbf_int8 = ArrowSbbf::new(&sbbf_int8, &DataType::Int8); | ||
|
||
// Setup for Int32 benchmarks | ||
let test_val_i32 = 42i32; | ||
let int32_array = Arc::new(Int32Array::from(vec![test_val_i32; 1])) as ArrayRef; | ||
let int32_field = Field::new("col", DataType::Int32, false); | ||
let sbbf_int32 = setup_sbbf(int32_array, int32_field); | ||
let arrow_sbbf_int32 = ArrowSbbf::new(&sbbf_int32, &DataType::Int32); | ||
|
||
c.bench_function("Sbbf::check i8", |b| { | ||
b.iter(|| { | ||
let result = sbbf_int8.check(&test_val_i8); | ||
hint::black_box(result); | ||
}) | ||
}); | ||
|
||
c.bench_function("ArrowSbbf::check i8 (coerce to i32)", |b| { | ||
b.iter(|| { | ||
let result = arrow_sbbf_int8.check(&test_val_i8); | ||
hint::black_box(result); | ||
}) | ||
}); | ||
|
||
c.bench_function("Sbbf::check i32", |b| { | ||
b.iter(|| { | ||
let result = sbbf_int32.check(&test_val_i32); | ||
hint::black_box(result); | ||
}) | ||
}); | ||
|
||
c.bench_function("ArrowSbbf::check i32 (no coercion)", |b| { | ||
b.iter(|| { | ||
let result = arrow_sbbf_int32.check(&test_val_i32); | ||
hint::black_box(result); | ||
}) | ||
}); | ||
} | ||
|
||
fn bench_decimal_types(c: &mut Criterion) { | ||
// Setup for Decimal128 small precision | ||
let test_val_dec_small = 123456i128; | ||
let test_bytes_dec_small = test_val_dec_small.to_le_bytes(); | ||
let dec_small_array = Arc::new( | ||
Decimal128Array::from(vec![test_val_dec_small; 1]) | ||
.with_precision_and_scale(5, 2) | ||
.unwrap(), | ||
) as ArrayRef; | ||
let dec_small_field = Field::new("col", DataType::Decimal128(5, 2), false); | ||
let sbbf_dec_small = setup_sbbf(dec_small_array, dec_small_field); | ||
let arrow_sbbf_dec_small = ArrowSbbf::new(&sbbf_dec_small, &DataType::Decimal128(5, 2)); | ||
|
||
// Setup for Decimal128 medium precision | ||
let test_val_dec_medium = 123456789012345i128; | ||
let test_bytes_dec_medium = test_val_dec_medium.to_le_bytes(); | ||
let dec_medium_array = Arc::new( | ||
Decimal128Array::from(vec![test_val_dec_medium; 1]) | ||
.with_precision_and_scale(15, 2) | ||
.unwrap(), | ||
) as ArrayRef; | ||
let dec_medium_field = Field::new("col", DataType::Decimal128(15, 2), false); | ||
let sbbf_dec_medium = setup_sbbf(dec_medium_array, dec_medium_field); | ||
let arrow_sbbf_dec_medium = ArrowSbbf::new(&sbbf_dec_medium, &DataType::Decimal128(15, 2)); | ||
|
||
// Setup for Decimal128 large precision | ||
let test_val_dec_large = 123456789012345678901234567890i128; | ||
let test_bytes_dec_large = test_val_dec_large.to_le_bytes(); | ||
let dec_large_array = Arc::new( | ||
Decimal128Array::from(vec![test_val_dec_large; 1]) | ||
.with_precision_and_scale(30, 2) | ||
.unwrap(), | ||
) as ArrayRef; | ||
let dec_large_field = Field::new("col", DataType::Decimal128(30, 2), false); | ||
let sbbf_dec_large = setup_sbbf(dec_large_array, dec_large_field); | ||
let arrow_sbbf_dec_large = ArrowSbbf::new(&sbbf_dec_large, &DataType::Decimal128(30, 2)); | ||
|
||
c.bench_function("Sbbf::check Decimal128(5,2)", |b| { | ||
b.iter(|| { | ||
let result = sbbf_dec_small.check(&test_bytes_dec_small[..]); | ||
hint::black_box(result); | ||
}) | ||
}); | ||
|
||
c.bench_function("ArrowSbbf::check Decimal128(5,2) (coerce to i32)", |b| { | ||
b.iter(|| { | ||
let result = arrow_sbbf_dec_small.check(&test_bytes_dec_small[..]); | ||
hint::black_box(result); | ||
}) | ||
}); | ||
|
||
c.bench_function("Sbbf::check Decimal128(15,2)", |b| { | ||
b.iter(|| { | ||
let result = sbbf_dec_medium.check(&test_bytes_dec_medium[..]); | ||
hint::black_box(result); | ||
}) | ||
}); | ||
|
||
c.bench_function("ArrowSbbf::check Decimal128(15,2) (coerce to i64)", |b| { | ||
b.iter(|| { | ||
let result = arrow_sbbf_dec_medium.check(&test_bytes_dec_medium[..]); | ||
hint::black_box(result); | ||
}) | ||
}); | ||
|
||
c.bench_function("Sbbf::check Decimal128(30,2)", |b| { | ||
b.iter(|| { | ||
let result = sbbf_dec_large.check(&test_bytes_dec_large[..]); | ||
hint::black_box(result); | ||
}) | ||
}); | ||
|
||
c.bench_function("ArrowSbbf::check Decimal128(30,2) (no coercion)", |b| { | ||
b.iter(|| { | ||
let result = arrow_sbbf_dec_large.check(&test_bytes_dec_large[..]); | ||
hint::black_box(result); | ||
}) | ||
}); | ||
} | ||
|
||
fn config() -> Criterion { | ||
Criterion::default().noise_threshold(0.05) | ||
} | ||
|
||
criterion_group! { | ||
name = benches_int; | ||
config = config(); | ||
targets = bench_integer_types | ||
} | ||
|
||
criterion_group! { | ||
name = benches_decimal; | ||
config = config(); | ||
targets = bench_decimal_types | ||
} | ||
|
||
criterion_main!(benches_int, benches_decimal); |
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.
Uh oh!
There was an error while loading. Please reload this page.
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.
Sbbf
ArrowSbbf
i8
i32
Decimal128(5,2)
Decimal128(15,2)
Decimal128(30,2)
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.
so this means that casting the bloom filter results is slower?