Skip to content
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
11 changes: 11 additions & 0 deletions datafusion/core/benches/aggregate_query_sql.rs
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,17 @@ fn criterion_benchmark(c: &mut Criterion) {
)
})
});

c.bench_function("array_agg_struct_query_group_by_mid_groups", |b| {
b.iter(|| {
query(
ctx.clone(),
&rt,
"SELECT u64_mid, array_agg(named_struct('market', dict10, 'price', f64)) \
FROM t GROUP BY u64_mid",
)
})
});
}

criterion_group!(benches, criterion_benchmark);
Expand Down
18 changes: 17 additions & 1 deletion datafusion/core/benches/data_utils/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@
use arrow::array::{
ArrayRef, Float32Array, Float64Array, RecordBatch, StringArray, StringViewBuilder,
UInt64Array,
builder::{Int64Builder, StringBuilder},
builder::{Int64Builder, StringBuilder, StringDictionaryBuilder},
};
use arrow::datatypes::Int32Type;
use arrow::datatypes::{DataType, Field, Schema, SchemaRef};
use datafusion::datasource::MemTable;
use datafusion::error::Result;
Expand Down Expand Up @@ -65,6 +66,11 @@ pub fn create_schema() -> Schema {
// Integers randomly selected from a narrow range of values such that
// there are a few distinct values, but they are repeated often.
Field::new("u64_narrow", DataType::UInt64, false),
Field::new(
"dict10",
DataType::Dictionary(Box::new(DataType::Int32), Box::new(DataType::Utf8)),
true,
),
])
}

Expand Down Expand Up @@ -109,6 +115,15 @@ fn create_record_batch(
.map(|_| rng.random_range(0..10))
.collect::<Vec<_>>();

let mut dict_builder = StringDictionaryBuilder::<Int32Type>::new();
for _ in 0..batch_size {
if rng.random::<f64>() > 0.9 {
dict_builder.append_null();
} else {
dict_builder.append_value(format!("market_{}", rng.random_range(0..10)));
}
}

RecordBatch::try_new(
schema,
vec![
Expand All @@ -118,6 +133,7 @@ fn create_record_batch(
Arc::new(UInt64Array::from(integer_values_wide)),
Arc::new(UInt64Array::from(integer_values_mid)),
Arc::new(UInt64Array::from(integer_values_narrow)),
Arc::new(dict_builder.finish()),
],
)
.unwrap()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ pub fn set_nulls<T: ArrowNumericType + Send>(
/// The `NullBuffer` is
/// * `true` (representing valid) for values that were `true` in filter
/// * `false` (representing null) for values that were `false` or `null` in filter
fn filter_to_nulls(filter: &BooleanArray) -> Option<NullBuffer> {
pub fn filter_to_nulls(filter: &BooleanArray) -> Option<NullBuffer> {
let (filter_bools, filter_nulls) = filter.clone().into_parts();
let filter_bools = NullBuffer::from(filter_bools);
NullBuffer::union(Some(&filter_bools), filter_nulls.as_ref())
Expand Down
Loading