Skip to content

Commit 9c03e02

Browse files
committed
perf(benchmarks): Add SQL queries to UnifiedQueryBenchmark
Add language (PPL/SQL) and queryPattern param dimensions for side-by-side comparison of equivalent queries across both languages. Remove separate UnifiedSqlQueryBenchmark in favor of unified class. Signed-off-by: Chen Dai <daichen@amazon.com>
1 parent 7d8613d commit 9c03e02

1 file changed

Lines changed: 61 additions & 14 deletions

File tree

benchmarks/src/jmh/java/org/opensearch/sql/api/UnifiedQueryBenchmark.java

Lines changed: 61 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
package org.opensearch.sql.api;
77

88
import java.sql.PreparedStatement;
9+
import java.util.Map;
910
import java.util.concurrent.TimeUnit;
1011
import org.apache.calcite.rel.RelNode;
1112
import org.apache.calcite.sql.dialect.SparkSqlDialect;
@@ -24,10 +25,12 @@
2425
import org.openjdk.jmh.annotations.Warmup;
2526
import org.opensearch.sql.api.compiler.UnifiedQueryCompiler;
2627
import org.opensearch.sql.api.transpiler.UnifiedQueryTranspiler;
28+
import org.opensearch.sql.executor.QueryType;
2729

2830
/**
29-
* JMH benchmark for measuring the overhead of unified query API components when processing queries.
30-
* This provides baseline metrics and guidance for API consumers during integration.
31+
* JMH benchmark for measuring the overhead of unified query API components when processing PPL and
32+
* SQL queries. The {@code language} and {@code queryPattern} parameters produce a cross-product,
33+
* enabling side-by-side comparison of equivalent queries across both languages.
3134
*/
3235
@Warmup(iterations = 2, time = 1)
3336
@Measurement(iterations = 5, time = 1)
@@ -37,25 +40,69 @@
3740
@Fork(value = 1)
3841
public class UnifiedQueryBenchmark extends UnifiedQueryTestBase {
3942

40-
/** Common query patterns for benchmarking. */
41-
@Param({
42-
"source = catalog.employees",
43-
"source = catalog.employees | where age > 30",
44-
"source = catalog.employees | stats count() by department",
45-
"source = catalog.employees | sort - age",
46-
"source = catalog.employees | where age > 25 | stats avg(age) by department | sort - department"
47-
})
48-
private String query;
43+
private static final Map<String, String> PPL_QUERIES =
44+
Map.of(
45+
"scan", "source = catalog.employees",
46+
"filter", "source = catalog.employees | where age > 30",
47+
"aggregate", "source = catalog.employees | stats count() by department",
48+
"sort", "source = catalog.employees | sort - age",
49+
"complex",
50+
"""
51+
source = catalog.employees \
52+
| where age > 25 \
53+
| stats avg(age) by department \
54+
| sort - department\
55+
""");
4956

50-
/** Transpiler for converting logical plans to SQL strings. */
51-
private UnifiedQueryTranspiler transpiler;
57+
private static final Map<String, String> SQL_QUERIES =
58+
Map.of(
59+
"scan", "SELECT * FROM catalog.employees",
60+
"filter",
61+
"""
62+
SELECT *
63+
FROM catalog.employees
64+
WHERE age > 30\
65+
""",
66+
"aggregate",
67+
"""
68+
SELECT department, count(*)
69+
FROM catalog.employees
70+
GROUP BY department\
71+
""",
72+
"sort",
73+
"""
74+
SELECT *
75+
FROM catalog.employees
76+
ORDER BY age DESC\
77+
""",
78+
"complex",
79+
"""
80+
SELECT department, avg(age)
81+
FROM catalog.employees
82+
WHERE age > 25
83+
GROUP BY department
84+
ORDER BY department\
85+
""");
86+
87+
@Param({"PPL", "SQL"})
88+
private String language;
89+
90+
@Param({"scan", "filter", "aggregate", "sort", "complex"})
91+
private String queryPattern;
5292

53-
/** Compiler for converting logical plans to executable statements. */
93+
private String query;
94+
private UnifiedQueryTranspiler transpiler;
5495
private UnifiedQueryCompiler compiler;
5596

97+
@Override
98+
protected QueryType queryType() {
99+
return QueryType.valueOf(language);
100+
}
101+
56102
@Setup(Level.Trial)
57103
public void setUpBenchmark() {
58104
super.setUp();
105+
query = (language.equals("PPL") ? PPL_QUERIES : SQL_QUERIES).get(queryPattern);
59106
transpiler = UnifiedQueryTranspiler.builder().dialect(SparkSqlDialect.DEFAULT).build();
60107
compiler = new UnifiedQueryCompiler(context);
61108
}

0 commit comments

Comments
 (0)