|
6 | 6 | package org.opensearch.sql.calcite.big5; |
7 | 7 |
|
8 | 8 | import java.io.IOException; |
9 | | -import java.util.LinkedHashMap; |
10 | 9 | import java.util.Locale; |
11 | 10 | import java.util.Map; |
12 | 11 | import org.junit.AfterClass; |
13 | 12 | import org.junit.FixMethodOrder; |
14 | | -import org.junit.Ignore; |
15 | 13 | import org.junit.Test; |
16 | 14 | import org.junit.runners.MethodSorters; |
| 15 | +import org.opensearch.common.collect.MapBuilder; |
17 | 16 | import org.opensearch.sql.ppl.PPLIntegTestCase; |
18 | 17 |
|
19 | 18 | @FixMethodOrder(MethodSorters.JVM) |
20 | 19 | public class PPLBig5IT extends PPLIntegTestCase { |
21 | | - private boolean initialized = false; |
22 | | - private static final Map<String, Long> summary = new LinkedHashMap<>(); |
| 20 | + private static final MapBuilder<String, Long> summary = MapBuilder.newMapBuilder(); |
23 | 21 |
|
24 | 22 | @Override |
25 | 23 | public void init() throws Exception { |
26 | 24 | super.init(); |
27 | 25 | loadIndex(Index.BIG5); |
28 | 26 | disableCalcite(); |
29 | | - // warm-up |
30 | | - if (!initialized) { |
31 | | - executeQuery("source=big5 | eval a = 1"); // trigger non-pushdown |
32 | | - initialized = true; |
33 | | - } |
34 | 27 | } |
35 | 28 |
|
36 | 29 | @AfterClass |
37 | 30 | public static void reset() throws IOException { |
38 | 31 | long total = 0; |
39 | | - for (long duration : summary.values()) { |
| 32 | + Map<String, Long> map = summary.immutableMap(); |
| 33 | + for (long duration : map.values()) { |
40 | 34 | total += duration; |
41 | 35 | } |
42 | 36 | System.out.println("Summary:"); |
43 | | - for (Map.Entry<String, Long> entry : summary.entrySet()) { |
44 | | - System.out.printf(Locale.ENGLISH, "%s: %d ms%n", entry.getKey(), entry.getValue()); |
45 | | - } |
| 37 | + map.entrySet().stream() |
| 38 | + .sorted(Map.Entry.comparingByKey()) |
| 39 | + .forEach( |
| 40 | + entry -> |
| 41 | + System.out.printf(Locale.ENGLISH, "%s: %d ms%n", entry.getKey(), entry.getValue())); |
46 | 42 | System.out.printf( |
47 | 43 | Locale.ENGLISH, |
48 | 44 | "Total %d queries succeed. Average duration: %d ms%n", |
49 | | - summary.size(), |
50 | | - total / summary.size()); |
| 45 | + map.size(), |
| 46 | + total / map.size()); |
51 | 47 | System.out.println(); |
52 | | - summary.clear(); |
53 | | - } |
54 | | - |
55 | | - protected void timing(String query, String ppl) throws IOException { |
56 | | - long start = System.currentTimeMillis(); |
57 | | - executeQuery(ppl); |
58 | | - long duration = System.currentTimeMillis() - start; |
59 | | - summary.put(query, duration); |
60 | 48 | } |
61 | 49 |
|
62 | 50 | @Test |
63 | 51 | public void asc_sort_timestamp() throws IOException { |
64 | 52 | String ppl = sanitize(loadFromFile("big5/queries/asc_sort_timestamp.ppl")); |
65 | | - timing("asc_sort_timestamp", ppl); |
| 53 | + timing(summary, "asc_sort_timestamp", ppl); |
66 | 54 | } |
67 | 55 |
|
68 | 56 | @Test |
69 | 57 | public void asc_sort_timestamp_can_match_shortcut() throws IOException { |
70 | 58 | String ppl = sanitize(loadFromFile("big5/queries/asc_sort_timestamp_can_match_shortcut.ppl")); |
71 | | - timing("asc_sort_timestamp_can_match_shortcut", ppl); |
| 59 | + timing(summary, "asc_sort_timestamp_can_match_shortcut", ppl); |
72 | 60 | } |
73 | 61 |
|
74 | 62 | @Test |
75 | 63 | public void asc_sort_timestamp_no_can_match_shortcut() throws IOException { |
76 | 64 | String ppl = |
77 | 65 | sanitize(loadFromFile("big5/queries/asc_sort_timestamp_no_can_match_shortcut.ppl")); |
78 | | - timing("asc_sort_timestamp_no_can_match_shortcut", ppl); |
| 66 | + timing(summary, "asc_sort_timestamp_no_can_match_shortcut", ppl); |
79 | 67 | } |
80 | 68 |
|
81 | 69 | @Test |
82 | 70 | public void asc_sort_with_after_timestamp() throws IOException { |
83 | 71 | String ppl = sanitize(loadFromFile("big5/queries/asc_sort_with_after_timestamp.ppl")); |
84 | | - timing("asc_sort_with_after_timestamp", ppl); |
| 72 | + timing(summary, "asc_sort_with_after_timestamp", ppl); |
85 | 73 | } |
86 | 74 |
|
87 | 75 | @Test |
88 | 76 | public void composite_date_histogram_daily() throws IOException { |
89 | 77 | String ppl = sanitize(loadFromFile("big5/queries/composite_date_histogram_daily.ppl")); |
90 | | - timing("composite_date_histogram_daily", ppl); |
| 78 | + timing(summary, "composite_date_histogram_daily", ppl); |
91 | 79 | } |
92 | 80 |
|
93 | 81 | @Test |
94 | 82 | public void composite_terms_keyword() throws IOException { |
95 | 83 | String ppl = sanitize(loadFromFile("big5/queries/composite_terms_keyword.ppl")); |
96 | | - timing("composite_terms_keyword", ppl); |
| 84 | + timing(summary, "composite_terms_keyword", ppl); |
97 | 85 | } |
98 | 86 |
|
99 | 87 | @Test |
100 | 88 | public void composite_terms() throws IOException { |
101 | 89 | String ppl = sanitize(loadFromFile("big5/queries/composite_terms.ppl")); |
102 | | - timing("composite_terms", ppl); |
| 90 | + timing(summary, "composite_terms", ppl); |
103 | 91 | } |
104 | 92 |
|
105 | 93 | @Test |
106 | 94 | public void date_histogram_hourly_agg() throws IOException { |
107 | 95 | String ppl = sanitize(loadFromFile("big5/queries/date_histogram_hourly_agg.ppl")); |
108 | | - timing("date_histogram_hourly_agg", ppl); |
| 96 | + timing(summary, "date_histogram_hourly_agg", ppl); |
109 | 97 | } |
110 | 98 |
|
111 | 99 | @Test |
112 | 100 | public void date_histogram_minute_agg() throws IOException { |
113 | 101 | String ppl = sanitize(loadFromFile("big5/queries/date_histogram_minute_agg.ppl")); |
114 | | - timing("date_histogram_minute_agg", ppl); |
| 102 | + timing(summary, "date_histogram_minute_agg", ppl); |
115 | 103 | } |
116 | 104 |
|
117 | 105 | @Test |
118 | 106 | public void test_default() throws IOException { |
119 | 107 | String ppl = sanitize(loadFromFile("big5/queries/default.ppl")); |
120 | | - timing("default", ppl); |
| 108 | + timing(summary, "default", ppl); |
121 | 109 | } |
122 | 110 |
|
123 | 111 | @Test |
124 | 112 | public void desc_sort_timestamp() throws IOException { |
125 | 113 | String ppl = sanitize(loadFromFile("big5/queries/desc_sort_timestamp.ppl")); |
126 | | - timing("desc_sort_timestamp", ppl); |
| 114 | + timing(summary, "desc_sort_timestamp", ppl); |
127 | 115 | } |
128 | 116 |
|
129 | 117 | @Test |
130 | 118 | public void desc_sort_timestamp_can_match_shortcut() throws IOException { |
131 | 119 | String ppl = sanitize(loadFromFile("big5/queries/desc_sort_timestamp_can_match_shortcut.ppl")); |
132 | | - timing("desc_sort_timestamp_can_match_shortcut", ppl); |
| 120 | + timing(summary, "desc_sort_timestamp_can_match_shortcut", ppl); |
133 | 121 | } |
134 | 122 |
|
135 | 123 | @Test |
136 | 124 | public void desc_sort_timestamp_no_can_match_shortcut() throws IOException { |
137 | 125 | String ppl = |
138 | 126 | sanitize(loadFromFile("big5/queries/desc_sort_timestamp_no_can_match_shortcut.ppl")); |
139 | | - timing("desc_sort_timestamp_no_can_match_shortcut", ppl); |
| 127 | + timing(summary, "desc_sort_timestamp_no_can_match_shortcut", ppl); |
140 | 128 | } |
141 | 129 |
|
142 | 130 | @Test |
143 | 131 | public void desc_sort_with_after_timestamp() throws IOException { |
144 | 132 | String ppl = sanitize(loadFromFile("big5/queries/desc_sort_with_after_timestamp.ppl")); |
145 | | - timing("desc_sort_with_after_timestamp", ppl); |
| 133 | + timing(summary, "desc_sort_with_after_timestamp", ppl); |
146 | 134 | } |
147 | 135 |
|
148 | 136 | @Test |
149 | 137 | public void keyword_in_range() throws IOException { |
150 | 138 | String ppl = sanitize(loadFromFile("big5/queries/keyword_in_range.ppl")); |
151 | | - timing("keyword_in_range", ppl); |
| 139 | + timing(summary, "keyword_in_range", ppl); |
152 | 140 | } |
153 | 141 |
|
154 | 142 | @Test |
155 | 143 | public void keyword_terms() throws IOException { |
156 | 144 | String ppl = sanitize(loadFromFile("big5/queries/keyword_terms.ppl")); |
157 | | - timing("keyword_terms", ppl); |
| 145 | + timing(summary, "keyword_terms", ppl); |
158 | 146 | } |
159 | 147 |
|
160 | 148 | @Test |
161 | 149 | public void keyword_terms_low_cardinality() throws IOException { |
162 | 150 | String ppl = sanitize(loadFromFile("big5/queries/keyword_terms_low_cardinality.ppl")); |
163 | | - timing("keyword_terms_low_cardinality", ppl); |
| 151 | + timing(summary, "keyword_terms_low_cardinality", ppl); |
164 | 152 | } |
165 | 153 |
|
166 | 154 | @Test |
167 | 155 | public void multi_terms_keyword() throws IOException { |
168 | 156 | String ppl = sanitize(loadFromFile("big5/queries/multi_terms_keyword.ppl")); |
169 | | - timing("multi_terms_keyword", ppl); |
| 157 | + timing(summary, "multi_terms_keyword", ppl); |
170 | 158 | } |
171 | 159 |
|
172 | 160 | @Test |
173 | 161 | public void query_string_on_message() throws IOException { |
174 | 162 | String ppl = sanitize(loadFromFile("big5/queries/query_string_on_message.ppl")); |
175 | | - timing("query_string_on_message", ppl); |
| 163 | + timing(summary, "query_string_on_message", ppl); |
176 | 164 | } |
177 | 165 |
|
178 | 166 | @Test |
179 | 167 | public void query_string_on_message_filtered() throws IOException { |
180 | 168 | String ppl = sanitize(loadFromFile("big5/queries/query_string_on_message_filtered.ppl")); |
181 | | - timing("query_string_on_message_filtered", ppl); |
| 169 | + timing(summary, "query_string_on_message_filtered", ppl); |
182 | 170 | } |
183 | 171 |
|
184 | 172 | @Test |
185 | 173 | public void query_string_on_message_filtered_sorted_num() throws IOException { |
186 | 174 | String ppl = |
187 | 175 | sanitize(loadFromFile("big5/queries/query_string_on_message_filtered_sorted_num.ppl")); |
188 | | - timing("query_string_on_message_filtered_sorted_num", ppl); |
| 176 | + timing(summary, "query_string_on_message_filtered_sorted_num", ppl); |
189 | 177 | } |
190 | 178 |
|
191 | 179 | @Test |
192 | 180 | public void range() throws IOException { |
193 | 181 | String ppl = sanitize(loadFromFile("big5/queries/range.ppl")); |
194 | | - timing("range", ppl); |
| 182 | + timing(summary, "range", ppl); |
195 | 183 | } |
196 | 184 |
|
197 | | - @Ignore("Failed to parse request payload") |
| 185 | + @Test |
198 | 186 | public void range_auto_date_histo() throws IOException { |
199 | 187 | String ppl = sanitize(loadFromFile("big5/queries/range_auto_date_histo.ppl")); |
200 | | - timing("range_auto_date_histo", ppl); |
| 188 | + timing(summary, "range_auto_date_histo", ppl); |
201 | 189 | } |
202 | 190 |
|
203 | | - @Ignore("Failed to parse request payload") |
| 191 | + @Test |
204 | 192 | public void range_auto_date_histo_with_metrics() throws IOException { |
205 | 193 | String ppl = sanitize(loadFromFile("big5/queries/range_auto_date_histo_with_metrics.ppl")); |
206 | | - timing("range_auto_date_histo_with_metrics", ppl); |
| 194 | + timing(summary, "range_auto_date_histo_with_metrics", ppl); |
207 | 195 | } |
208 | 196 |
|
209 | 197 | @Test |
210 | 198 | public void range_numeric() throws IOException { |
211 | 199 | String ppl = sanitize(loadFromFile("big5/queries/range_numeric.ppl")); |
212 | | - timing("range_numeric", ppl); |
| 200 | + timing(summary, "range_numeric", ppl); |
213 | 201 | } |
214 | 202 |
|
215 | 203 | @Test |
216 | 204 | public void range_field_conjunction_big_range_big_term_query() throws IOException { |
217 | 205 | String ppl = |
218 | 206 | sanitize(loadFromFile("big5/queries/range_field_conjunction_big_range_big_term_query.ppl")); |
219 | | - timing("range_field_conjunction_big_range_big_term_query", ppl); |
| 207 | + timing(summary, "range_field_conjunction_big_range_big_term_query", ppl); |
220 | 208 | } |
221 | 209 |
|
222 | 210 | @Test |
223 | 211 | public void range_field_conjunction_small_range_big_term_query() throws IOException { |
224 | 212 | String ppl = |
225 | 213 | sanitize( |
226 | 214 | loadFromFile("big5/queries/range_field_conjunction_small_range_big_term_query.ppl")); |
227 | | - timing("range_field_conjunction_small_range_big_term_query", ppl); |
| 215 | + timing(summary, "range_field_conjunction_small_range_big_term_query", ppl); |
228 | 216 | } |
229 | 217 |
|
230 | 218 | @Test |
231 | 219 | public void range_field_conjunction_small_range_small_term_query() throws IOException { |
232 | 220 | String ppl = |
233 | 221 | sanitize( |
234 | 222 | loadFromFile("big5/queries/range_field_conjunction_small_range_small_term_query.ppl")); |
235 | | - timing("range_field_conjunction_small_range_small_term_query", ppl); |
| 223 | + timing(summary, "range_field_conjunction_small_range_small_term_query", ppl); |
236 | 224 | } |
237 | 225 |
|
238 | 226 | @Test |
239 | 227 | public void range_field_disjunction_big_range_small_term_query() throws IOException { |
240 | 228 | String ppl = |
241 | 229 | sanitize( |
242 | 230 | loadFromFile("big5/queries/range_field_disjunction_big_range_small_term_query.ppl")); |
243 | | - timing("range_field_disjunction_big_range_small_term_query", ppl); |
| 231 | + timing(summary, "range_field_disjunction_big_range_small_term_query", ppl); |
244 | 232 | } |
245 | 233 |
|
246 | 234 | @Test |
247 | 235 | public void range_with_asc_sort() throws IOException { |
248 | 236 | String ppl = sanitize(loadFromFile("big5/queries/range_with_asc_sort.ppl")); |
249 | | - timing("range_with_asc_sort", ppl); |
| 237 | + timing(summary, "range_with_asc_sort", ppl); |
250 | 238 | } |
251 | 239 |
|
252 | 240 | @Test |
253 | 241 | public void range_with_desc_sort() throws IOException { |
254 | 242 | String ppl = sanitize(loadFromFile("big5/queries/range_with_desc_sort.ppl")); |
255 | | - timing("range_with_desc_sort", ppl); |
| 243 | + timing(summary, "range_with_desc_sort", ppl); |
256 | 244 | } |
257 | 245 |
|
258 | 246 | @Test |
259 | 247 | public void scroll() throws IOException { |
260 | 248 | String ppl = sanitize(loadFromFile("big5/queries/scroll.ppl")); |
261 | | - timing("scroll", ppl); |
| 249 | + timing(summary, "scroll", ppl); |
262 | 250 | } |
263 | 251 |
|
264 | 252 | @Test |
265 | 253 | public void sort_keyword_can_match_shortcut() throws IOException { |
266 | 254 | String ppl = sanitize(loadFromFile("big5/queries/sort_keyword_can_match_shortcut.ppl")); |
267 | | - timing("sort_keyword_can_match_shortcut", ppl); |
| 255 | + timing(summary, "sort_keyword_can_match_shortcut", ppl); |
268 | 256 | } |
269 | 257 |
|
270 | 258 | @Test |
271 | 259 | public void sort_keyword_no_can_match_shortcut() throws IOException { |
272 | 260 | String ppl = sanitize(loadFromFile("big5/queries/sort_keyword_no_can_match_shortcut.ppl")); |
273 | | - timing("sort_keyword_no_can_match_shortcut", ppl); |
| 261 | + timing(summary, "sort_keyword_no_can_match_shortcut", ppl); |
274 | 262 | } |
275 | 263 |
|
276 | 264 | @Test |
277 | 265 | public void sort_numeric_asc() throws IOException { |
278 | 266 | String ppl = sanitize(loadFromFile("big5/queries/sort_numeric_asc.ppl")); |
279 | | - timing("sort_numeric_asc", ppl); |
| 267 | + timing(summary, "sort_numeric_asc", ppl); |
280 | 268 | } |
281 | 269 |
|
282 | 270 | @Test |
283 | 271 | public void sort_numeric_asc_with_match() throws IOException { |
284 | 272 | String ppl = sanitize(loadFromFile("big5/queries/sort_numeric_asc_with_match.ppl")); |
285 | | - timing("sort_numeric_asc_with_match", ppl); |
| 273 | + timing(summary, "sort_numeric_asc_with_match", ppl); |
286 | 274 | } |
287 | 275 |
|
288 | 276 | @Test |
289 | 277 | public void sort_numeric_desc() throws IOException { |
290 | 278 | String ppl = sanitize(loadFromFile("big5/queries/sort_numeric_desc.ppl")); |
291 | | - timing("sort_numeric_desc", ppl); |
| 279 | + timing(summary, "sort_numeric_desc", ppl); |
292 | 280 | } |
293 | 281 |
|
294 | 282 | @Test |
295 | 283 | public void sort_numeric_desc_with_match() throws IOException { |
296 | 284 | String ppl = sanitize(loadFromFile("big5/queries/sort_numeric_desc_with_match.ppl")); |
297 | | - timing("sort_numeric_desc_with_match", ppl); |
| 285 | + timing(summary, "sort_numeric_desc_with_match", ppl); |
298 | 286 | } |
299 | 287 |
|
300 | 288 | @Test |
301 | 289 | public void term() throws IOException { |
302 | 290 | String ppl = sanitize(loadFromFile("big5/queries/term.ppl")); |
303 | | - timing("term", ppl); |
| 291 | + timing(summary, "term", ppl); |
304 | 292 | } |
305 | 293 |
|
306 | 294 | @Test |
307 | 295 | public void terms_significant_1() throws IOException { |
308 | 296 | String ppl = sanitize(loadFromFile("big5/queries/terms_significant_1.ppl")); |
309 | | - timing("terms_significant_1", ppl); |
| 297 | + timing(summary, "terms_significant_1", ppl); |
310 | 298 | } |
311 | 299 |
|
312 | 300 | @Test |
313 | 301 | public void terms_significant_2() throws IOException { |
314 | 302 | String ppl = sanitize(loadFromFile("big5/queries/terms_significant_2.ppl")); |
315 | | - timing("terms_significant_2", ppl); |
| 303 | + timing(summary, "terms_significant_2", ppl); |
316 | 304 | } |
317 | 305 | } |
0 commit comments