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

Convert rows to arrays (#2677) #2826

Merged
merged 3 commits into from
Oct 6, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
140 changes: 37 additions & 103 deletions arrow/benches/row_format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,161 +20,95 @@ extern crate criterion;
extern crate core;

use arrow::array::ArrayRef;
use arrow::datatypes::{DataType, Int64Type, UInt64Type};
use arrow::datatypes::{Int64Type, UInt64Type};
use arrow::row::{RowConverter, SortField};
use arrow::util::bench_util::{
create_primitive_array, create_string_array_with_len, create_string_dict_array,
};
use arrow_array::types::Int32Type;
use arrow_array::Array;
use criterion::{black_box, Criterion};
use std::sync::Arc;

fn row_bench(c: &mut Criterion) {
let cols = vec![Arc::new(create_primitive_array::<UInt64Type>(4096, 0.)) as ArrayRef];
fn do_bench(c: &mut Criterion, name: &str, cols: Vec<ArrayRef>) {
let fields: Vec<_> = cols
.iter()
.map(|x| SortField::new(x.data_type().clone()))
.collect();

c.bench_function("row_batch 4096 u64(0)", |b| {
c.bench_function(&format!("convert_columns {}", name), |b| {
b.iter(|| {
let mut converter = RowConverter::new(vec![SortField::new(DataType::UInt64)]);
black_box(converter.convert_columns(&cols))
let mut converter = RowConverter::new(fields.clone());
black_box(converter.convert_columns(&cols).unwrap())
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Before, the dictionary benchmarks were actually benchmarking the time to error on the schema, as the DataType was incorrect 😱

This unwrap should prevent something similar happening in future

});
});

let cols = vec![Arc::new(create_primitive_array::<Int64Type>(4096, 0.)) as ArrayRef];
let mut converter = RowConverter::new(fields);
let rows = converter.convert_columns(&cols).unwrap();

c.bench_function("row_batch 4096 i64(0)", |b| {
b.iter(|| {
let mut converter = RowConverter::new(vec![SortField::new(DataType::Int64)]);
black_box(converter.convert_columns(&cols))
});
c.bench_function(&format!("convert_rows {}", name), |b| {
b.iter(|| black_box(converter.convert_rows(&rows).unwrap()));
});
}

fn row_bench(c: &mut Criterion) {
let cols = vec![Arc::new(create_primitive_array::<UInt64Type>(4096, 0.)) as ArrayRef];
do_bench(c, "4096 u64(0)", cols);

let cols = vec![Arc::new(create_primitive_array::<Int64Type>(4096, 0.)) as ArrayRef];
do_bench(c, "4096 i64(0)", cols);

let cols =
vec![Arc::new(create_string_array_with_len::<i32>(4096, 0., 10)) as ArrayRef];

c.bench_function("row_batch 4096 string(10, 0)", |b| {
b.iter(|| {
let mut converter = RowConverter::new(vec![SortField::new(DataType::Utf8)]);
black_box(converter.convert_columns(&cols))
});
});
do_bench(c, "4096 string(10, 0)", cols);

let cols =
vec![Arc::new(create_string_array_with_len::<i32>(4096, 0., 30)) as ArrayRef];

c.bench_function("row_batch 4096 string(30, 0)", |b| {
b.iter(|| {
let mut converter = RowConverter::new(vec![SortField::new(DataType::Utf8)]);
black_box(converter.convert_columns(&cols))
});
});
do_bench(c, "4096 string(30, 0)", cols);

let cols =
vec![Arc::new(create_string_array_with_len::<i32>(4096, 0., 100)) as ArrayRef];

c.bench_function("row_batch 4096 string(100, 0)", |b| {
b.iter(|| {
let mut converter = RowConverter::new(vec![SortField::new(DataType::Utf8)]);
black_box(converter.convert_columns(&cols))
});
});
do_bench(c, "4096 string(100, 0)", cols);

let cols =
vec![Arc::new(create_string_array_with_len::<i32>(4096, 0.5, 100)) as ArrayRef];

c.bench_function("row_batch 4096 string(100, 0.5)", |b| {
b.iter(|| {
let mut converter = RowConverter::new(vec![SortField::new(DataType::Utf8)]);
black_box(converter.convert_columns(&cols))
});
});
do_bench(c, "4096 string(100, 0.5)", cols);

let cols =
vec![Arc::new(create_string_dict_array::<Int32Type>(4096, 0., 10)) as ArrayRef];

c.bench_function("row_batch 4096 string_dictionary(10, 0)", |b| {
b.iter(|| {
let mut converter = RowConverter::new(vec![SortField::new(DataType::Utf8)]);
black_box(converter.convert_columns(&cols))
});
});
do_bench(c, "4096 string_dictionary(10, 0)", cols);

let cols =
vec![Arc::new(create_string_dict_array::<Int32Type>(4096, 0., 30)) as ArrayRef];

c.bench_function("row_batch 4096 string_dictionary(30, 0)", |b| {
b.iter(|| {
let mut converter = RowConverter::new(vec![SortField::new(DataType::Utf8)]);
black_box(converter.convert_columns(&cols))
});
});
do_bench(c, "4096 string_dictionary(30, 0)", cols);

let cols =
vec![Arc::new(create_string_dict_array::<Int32Type>(4096, 0., 100)) as ArrayRef];

c.bench_function("row_batch 4096 string_dictionary(100, 0)", |b| {
b.iter(|| {
let mut converter = RowConverter::new(vec![SortField::new(DataType::Utf8)]);
black_box(converter.convert_columns(&cols))
});
});
do_bench(c, "4096 string_dictionary(100, 0)", cols);

let cols =
vec![Arc::new(create_string_dict_array::<Int32Type>(4096, 0.5, 100)) as ArrayRef];
do_bench(c, "4096 string_dictionary(100, 0.5)", cols);

c.bench_function("row_batch 4096 string_dictionary(100, 0.5)", |b| {
b.iter(|| {
let mut converter = RowConverter::new(vec![SortField::new(DataType::Utf8)]);
black_box(converter.convert_columns(&cols))
});
});

let cols = [
let cols = vec![
Arc::new(create_string_array_with_len::<i32>(4096, 0.5, 20)) as ArrayRef,
Arc::new(create_string_array_with_len::<i32>(4096, 0., 30)) as ArrayRef,
Arc::new(create_string_array_with_len::<i32>(4096, 0., 100)) as ArrayRef,
Arc::new(create_primitive_array::<Int64Type>(4096, 0.)) as ArrayRef,
];

let fields = [
SortField::new(DataType::Utf8),
SortField::new(DataType::Utf8),
SortField::new(DataType::Utf8),
SortField::new(DataType::Int64),
];

c.bench_function(
"row_batch 4096 string(20, 0.5), string(30, 0), string(100, 0), i64(0)",
|b| {
b.iter(|| {
let mut converter = RowConverter::new(fields.to_vec());
black_box(converter.convert_columns(&cols))
});
},
do_bench(
c,
"4096 string(20, 0.5), string(30, 0), string(100, 0), i64(0)",
cols,
);

let cols = [
let cols = vec![
Arc::new(create_string_dict_array::<Int32Type>(4096, 0.5, 20)) as ArrayRef,
Arc::new(create_string_dict_array::<Int32Type>(4096, 0., 30)) as ArrayRef,
Arc::new(create_string_dict_array::<Int32Type>(4096, 0., 100)) as ArrayRef,
Arc::new(create_primitive_array::<Int64Type>(4096, 0.)) as ArrayRef,
];

let fields = [
SortField::new(DataType::Utf8),
SortField::new(DataType::Utf8),
SortField::new(DataType::Utf8),
SortField::new(DataType::Int64),
];

c.bench_function(
"row_batch 4096 string_dictionary(20, 0.5), string_dictionary(30, 0), string_dictionary(100, 0), i64(0)",
|b| {
b.iter(|| {
let mut converter = RowConverter::new(fields.to_vec());
black_box(converter.convert_columns(&cols))
});
},
);
do_bench(c, "4096 4096 string_dictionary(20, 0.5), string_dictionary(30, 0), string_dictionary(100, 0), i64(0)", cols);
}

criterion_group!(benches, row_bench);
Expand Down
Loading