|
6 | 6 | package org.opensearch.sql.api; |
7 | 7 |
|
8 | 8 | import java.sql.PreparedStatement; |
| 9 | +import java.util.Map; |
9 | 10 | import java.util.concurrent.TimeUnit; |
10 | 11 | import org.apache.calcite.rel.RelNode; |
11 | 12 | import org.apache.calcite.sql.dialect.SparkSqlDialect; |
|
24 | 25 | import org.openjdk.jmh.annotations.Warmup; |
25 | 26 | import org.opensearch.sql.api.compiler.UnifiedQueryCompiler; |
26 | 27 | import org.opensearch.sql.api.transpiler.UnifiedQueryTranspiler; |
| 28 | +import org.opensearch.sql.executor.QueryType; |
27 | 29 |
|
28 | 30 | /** |
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. |
31 | 34 | */ |
32 | 35 | @Warmup(iterations = 2, time = 1) |
33 | 36 | @Measurement(iterations = 5, time = 1) |
|
37 | 40 | @Fork(value = 1) |
38 | 41 | public class UnifiedQueryBenchmark extends UnifiedQueryTestBase { |
39 | 42 |
|
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 | + """); |
49 | 56 |
|
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; |
52 | 92 |
|
53 | | - /** Compiler for converting logical plans to executable statements. */ |
| 93 | + private String query; |
| 94 | + private UnifiedQueryTranspiler transpiler; |
54 | 95 | private UnifiedQueryCompiler compiler; |
55 | 96 |
|
| 97 | + @Override |
| 98 | + protected QueryType queryType() { |
| 99 | + return QueryType.valueOf(language); |
| 100 | + } |
| 101 | + |
56 | 102 | @Setup(Level.Trial) |
57 | 103 | public void setUpBenchmark() { |
58 | 104 | super.setUp(); |
| 105 | + query = (language.equals("PPL") ? PPL_QUERIES : SQL_QUERIES).get(queryPattern); |
59 | 106 | transpiler = UnifiedQueryTranspiler.builder().dialect(SparkSqlDialect.DEFAULT).build(); |
60 | 107 | compiler = new UnifiedQueryCompiler(context); |
61 | 108 | } |
|
0 commit comments