Skip to content

Commit 0f0e478

Browse files
Start setting up tpch planning benchmarks
1 parent 28ca6d1 commit 0f0e478

File tree

1 file changed

+58
-0
lines changed

1 file changed

+58
-0
lines changed

datafusion/core/benches/sql_planner.rs

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,44 @@ pub fn create_table_provider(column_prefix: &str, num_columns: usize) -> Arc<Mem
6060
MemTable::try_new(schema, vec![]).map(Arc::new).unwrap()
6161
}
6262

63+
pub fn create_tpch_schemas() -> [(String, Schema); 2] {
64+
let lineitem_schema = Schema::new(vec![
65+
Field::new("l_orderkey", DataType::Int32, false),
66+
Field::new("l_partkey", DataType::Int32, false),
67+
Field::new("l_suppkey", DataType::Int32, false),
68+
Field::new("l_linenumber", DataType::Int32, false),
69+
Field::new("l_quantity", DataType::Float64, false),
70+
Field::new("l_extendedprice", DataType::Float64, false),
71+
Field::new("l_discount", DataType::Float64, false),
72+
Field::new("l_tax", DataType::Float64, false),
73+
Field::new("l_returnflag", DataType::Utf8, false),
74+
Field::new("l_linestatus", DataType::Utf8, false),
75+
Field::new("l_shipdate", DataType::Date32, false),
76+
Field::new("l_commitdate", DataType::Date32, false),
77+
Field::new("l_receiptdate", DataType::Date32, false),
78+
Field::new("l_shipinstruct", DataType::Utf8, false),
79+
Field::new("l_shipmode", DataType::Utf8, false),
80+
Field::new("l_comment", DataType::Utf8, false),
81+
]);
82+
83+
let orders_schema = Schema::new(vec![
84+
Field::new("o_orderkey", DataType::Int32, false),
85+
Field::new("o_custkey", DataType::Int32, false),
86+
Field::new("o_orderstatus", DataType::Utf8, false),
87+
Field::new("o_totalprice", DataType::Float64, false),
88+
Field::new("o_orderdate", DataType::Date32, false),
89+
Field::new("o_orderpriority", DataType::Utf8, false),
90+
Field::new("o_clerk", DataType::Utf8, false),
91+
Field::new("o_shippriority", DataType::Int32, false),
92+
Field::new("o_comment", DataType::Utf8, false),
93+
]);
94+
95+
return [
96+
("lineitem".to_string(), lineitem_schema),
97+
("orders".to_string(), orders_schema),
98+
];
99+
}
100+
63101
fn create_context() -> SessionContext {
64102
let ctx = SessionContext::new();
65103
ctx.register_table("t1", create_table_provider("a", 200))
@@ -68,6 +106,16 @@ fn create_context() -> SessionContext {
68106
.unwrap();
69107
ctx.register_table("t700", create_table_provider("c", 700))
70108
.unwrap();
109+
110+
let tpch_schemas = create_tpch_schemas();
111+
tpch_schemas.iter().for_each(|(name, schema)| {
112+
ctx.register_table(
113+
name,
114+
Arc::new(MemTable::try_new(Arc::new(schema.clone()), vec![]).unwrap()),
115+
)
116+
.unwrap();
117+
});
118+
71119
ctx
72120
}
73121

@@ -115,6 +163,16 @@ fn criterion_benchmark(c: &mut Criterion) {
115163
)
116164
})
117165
});
166+
167+
let q1_sql = std::fs::read_to_string("../../benchmarks/queries/q1.sql").unwrap();
168+
c.bench_function("physical_plan_tpch_q1", |b| {
169+
b.iter(|| physical_plan(&ctx, &q1_sql))
170+
});
171+
172+
let q12_sql = std::fs::read_to_string("../../benchmarks/queries/q12.sql").unwrap();
173+
c.bench_function("physical_plan_tpch_q12", |b| {
174+
b.iter(|| physical_plan(&ctx, &q12_sql))
175+
});
118176
}
119177

120178
criterion_group!(benches, criterion_benchmark);

0 commit comments

Comments
 (0)