Skip to content

Commit 635e7b5

Browse files
committed
Add nested alias bench for expr_schema with metadata
- Add new bench for expr_schema that tests nested alias behavior with metadata - Update Cargo.toml to include bench for expr_schema - Implement bench in Rust to test nested alias generation with metadata
1 parent 269e49f commit 635e7b5

2 files changed

Lines changed: 76 additions & 0 deletions

File tree

‎datafusion/expr/Cargo.toml‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,3 +78,7 @@ insta = { workspace = true }
7878
[[bench]]
7979
name = "normalize_columns"
8080
harness = false
81+
82+
[[bench]]
83+
name = "expr_schema"
84+
harness = false
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
// Licensed to the Apache Software Foundation (ASF) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The ASF licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
18+
use std::collections::HashMap;
19+
use std::hint::black_box;
20+
use std::sync::Arc;
21+
22+
use arrow::datatypes::{DataType, Field};
23+
use criterion::{BenchmarkId, Criterion, criterion_group, criterion_main};
24+
use datafusion_common::DFSchema;
25+
use datafusion_common::metadata::FieldMetadata;
26+
use datafusion_expr::{ExprSchemable, col};
27+
28+
fn nested_alias_to_field(c: &mut Criterion) {
29+
let source_metadata = HashMap::from([
30+
("keep".to_string(), "base".to_string()),
31+
("override".to_string(), "base".to_string()),
32+
]);
33+
let schema = DFSchema::from_unqualified_fields(
34+
vec![Arc::new(
35+
Field::new("source", DataType::Int32, false).with_metadata(source_metadata),
36+
)]
37+
.into(),
38+
HashMap::new(),
39+
)
40+
.unwrap();
41+
42+
let mut group = c.benchmark_group("nested_alias_to_field");
43+
for depth in [0, 1, 4, 8, 12] {
44+
for with_metadata in [false, true] {
45+
let mut expr = col("source");
46+
for index in 0..depth {
47+
expr = if with_metadata {
48+
expr.alias_with_metadata(
49+
format!("alias{index}"),
50+
Some(FieldMetadata::from(HashMap::from([(
51+
"override".to_string(),
52+
index.to_string(),
53+
)]))),
54+
)
55+
} else {
56+
expr.alias(format!("alias{index}"))
57+
};
58+
}
59+
// Rust API builds directly nested aliases, avoiding SQL's surface syntax limitations.
60+
let mode = if with_metadata { "metadata" } else { "plain" };
61+
group.bench_with_input(BenchmarkId::new(mode, depth), &expr, |b, expr| {
62+
b.iter(|| {
63+
black_box(black_box(expr).to_field(black_box(&schema)).unwrap())
64+
})
65+
});
66+
}
67+
}
68+
group.finish();
69+
}
70+
71+
criterion_group!(benches, nested_alias_to_field);
72+
criterion_main!(benches);

0 commit comments

Comments
 (0)