Skip to content

Commit 83e6937

Browse files
committed
perf(benchmarks): Add JMH benchmark for Calcite SQL planning path
Add UnifiedSqlQueryBenchmark with SQL equivalents of existing PPL benchmarks for plan, transpile, and compile operations. Signed-off-by: Chen Dai <daichen@amazon.com>
1 parent df87a7a commit 83e6937

1 file changed

Lines changed: 88 additions & 0 deletions

File tree

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
/*
2+
* Copyright OpenSearch Contributors
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
package org.opensearch.sql.api;
7+
8+
import java.sql.PreparedStatement;
9+
import java.util.concurrent.TimeUnit;
10+
import org.apache.calcite.rel.RelNode;
11+
import org.apache.calcite.sql.dialect.SparkSqlDialect;
12+
import org.openjdk.jmh.annotations.Benchmark;
13+
import org.openjdk.jmh.annotations.BenchmarkMode;
14+
import org.openjdk.jmh.annotations.Fork;
15+
import org.openjdk.jmh.annotations.Level;
16+
import org.openjdk.jmh.annotations.Measurement;
17+
import org.openjdk.jmh.annotations.Mode;
18+
import org.openjdk.jmh.annotations.OutputTimeUnit;
19+
import org.openjdk.jmh.annotations.Param;
20+
import org.openjdk.jmh.annotations.Scope;
21+
import org.openjdk.jmh.annotations.Setup;
22+
import org.openjdk.jmh.annotations.State;
23+
import org.openjdk.jmh.annotations.TearDown;
24+
import org.openjdk.jmh.annotations.Warmup;
25+
import org.opensearch.sql.api.compiler.UnifiedQueryCompiler;
26+
import org.opensearch.sql.api.transpiler.UnifiedQueryTranspiler;
27+
import org.opensearch.sql.executor.QueryType;
28+
29+
/**
30+
* JMH benchmark for measuring the overhead of the Calcite native SQL planning path. Provides
31+
* baseline metrics comparable to the PPL benchmarks in {@link UnifiedQueryBenchmark}.
32+
*/
33+
@Warmup(iterations = 2, time = 1)
34+
@Measurement(iterations = 5, time = 1)
35+
@BenchmarkMode(Mode.AverageTime)
36+
@OutputTimeUnit(TimeUnit.MILLISECONDS)
37+
@State(Scope.Thread)
38+
@Fork(value = 1)
39+
public class UnifiedSqlQueryBenchmark extends UnifiedQueryTestBase {
40+
41+
@Param({
42+
"SELECT * FROM catalog.employees",
43+
"SELECT * FROM catalog.employees WHERE age > 30",
44+
"SELECT department, count(*) FROM catalog.employees GROUP BY department",
45+
"SELECT * FROM catalog.employees ORDER BY age DESC",
46+
"SELECT * FROM catalog.employees WHERE age > 25 GROUP BY department ORDER BY department"
47+
})
48+
private String query;
49+
50+
private UnifiedQueryTranspiler transpiler;
51+
private UnifiedQueryCompiler compiler;
52+
53+
@Override
54+
protected QueryType queryType() {
55+
return QueryType.SQL;
56+
}
57+
58+
@Setup(Level.Trial)
59+
public void setUpBenchmark() {
60+
super.setUp();
61+
transpiler = UnifiedQueryTranspiler.builder().dialect(SparkSqlDialect.DEFAULT).build();
62+
compiler = new UnifiedQueryCompiler(context);
63+
}
64+
65+
@TearDown(Level.Trial)
66+
public void tearDownBenchmark() throws Exception {
67+
super.tearDown();
68+
}
69+
70+
@Benchmark
71+
public RelNode planQuery() {
72+
return planner.plan(query);
73+
}
74+
75+
@Benchmark
76+
public String transpileToSql() {
77+
RelNode plan = planner.plan(query);
78+
return transpiler.toSql(plan);
79+
}
80+
81+
@Benchmark
82+
public void compileQuery() throws Exception {
83+
RelNode plan = planner.plan(query);
84+
try (PreparedStatement stmt = compiler.compile(plan)) {
85+
// Statement is auto-closed after benchmark iteration
86+
}
87+
}
88+
}

0 commit comments

Comments
 (0)