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] Add BooleanArray based row selection #6624

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
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
2 changes: 1 addition & 1 deletion parquet/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ harness = false
[[bench]]
name = "row_selector"
harness = false
required-features = ["arrow"]
required-features = ["arrow", "experimental"]

[lib]
bench = false
113 changes: 76 additions & 37 deletions parquet/benches/row_selector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

use arrow_array::BooleanArray;
use criterion::*;
use parquet::arrow::arrow_reader::RowSelection;
use parquet::arrow::arrow_reader::{BooleanRowSelection, RowSelection};
use rand::Rng;

/// Generates a random RowSelection with a specified selection ratio.
Expand All @@ -40,47 +40,86 @@ fn generate_random_row_selection(total_rows: usize, selection_ratio: f64) -> Boo

fn criterion_benchmark(c: &mut Criterion) {
let total_rows = 300_000;
let selection_ratio = 1.0 / 3.0;
let selection_ratios = [0.000_01, 0.001, 0.1, 0.3];

// Generate two random RowSelections with approximately 1/3 of the rows selected.
let row_selection_a =
RowSelection::from_filters(&[generate_random_row_selection(total_rows, selection_ratio)]);
let row_selection_b =
RowSelection::from_filters(&[generate_random_row_selection(total_rows, selection_ratio)]);
for ratio in selection_ratios {
let slice_selection_a =
RowSelection::from_filters(&[generate_random_row_selection(total_rows, ratio)]);
let slice_selection_b =
RowSelection::from_filters(&[generate_random_row_selection(total_rows, ratio)]);

// Benchmark the intersection of the two RowSelections.
c.bench_function("intersection", |b| {
b.iter(|| {
let intersection = row_selection_a.intersection(&row_selection_b);
criterion::black_box(intersection);
})
});
let boolean_selection_a = BooleanRowSelection::from(slice_selection_a.clone());
let boolean_selection_b = BooleanRowSelection::from(slice_selection_b.clone());

c.bench_function("union", |b| {
b.iter(|| {
let union = row_selection_a.union(&row_selection_b);
criterion::black_box(union);
})
});
// Benchmark the intersection of the two RowSelections.
c.bench_function(&format!("slice intersection {}", ratio), |b| {
b.iter(|| {
let intersection = slice_selection_a.intersection(&slice_selection_b);
criterion::black_box(intersection);
})
});

c.bench_function("from_filters", |b| {
let boolean_array = generate_random_row_selection(total_rows, selection_ratio);
b.iter(|| {
let array = boolean_array.clone();
let selection = RowSelection::from_filters(&[array]);
criterion::black_box(selection);
})
});
c.bench_function(&format!("boolean intersection {}", ratio), |b| {
b.iter(|| {
let intersection = boolean_selection_a.intersection(&boolean_selection_b);
criterion::black_box(intersection);
})
});

c.bench_function("and_then", |b| {
let selected = row_selection_a.row_count();
let sub_selection =
RowSelection::from_filters(&[generate_random_row_selection(selected, selection_ratio)]);
b.iter(|| {
let result = row_selection_a.and_then(&sub_selection);
criterion::black_box(result);
})
});
c.bench_function(&format!("slice union {}", ratio), |b| {
b.iter(|| {
let union = slice_selection_a.union(&slice_selection_b);
criterion::black_box(union);
})
});

c.bench_function(&format!("boolean union {}", ratio), |b| {
b.iter(|| {
let union = boolean_selection_a.union(&boolean_selection_b);
criterion::black_box(union);
})
});

c.bench_function(&format!("slice from_filters {}", ratio), |b| {
let boolean_array = generate_random_row_selection(total_rows, ratio);
b.iter(|| {
let array = boolean_array.clone();
let selection = RowSelection::from_filters(&[array]);
criterion::black_box(selection);
})
});

c.bench_function(&format!("boolean from_filters {}", ratio), |b| {
let boolean_array = generate_random_row_selection(total_rows, ratio);
b.iter(|| {
let array = boolean_array.clone();
let selection = BooleanRowSelection::from_filters(&[array]);
criterion::black_box(selection);
})
});

c.bench_function(&format!("slice and_then {}", ratio), |b| {
let selected = slice_selection_a.row_count();
let sub_selection =
RowSelection::from_filters(&[generate_random_row_selection(selected, ratio)]);
b.iter(|| {
let result = slice_selection_a.and_then(&sub_selection);
criterion::black_box(result);
})
});

c.bench_function(&format!("boolean and_then {}", ratio), |b| {
let selected = boolean_selection_a.row_count();
let sub_selection =
BooleanRowSelection::from_filters(&[generate_random_row_selection(
selected, ratio,
)]);
b.iter(|| {
let result = boolean_selection_a.and_then(&sub_selection);
criterion::black_box(result);
})
});
}
}

criterion_group!(benches, criterion_benchmark);
Expand Down
Loading
Loading