Commit bb8d9b2
committed
Extend rewrite to dc / distinct_count via canonical-name translation
PPL eventstats accepts three aliases for the cardinality aggregation —
dc, distinct_count, distinct_count_approx — all resolving to
BuiltinFunctionName.DISTINCT_COUNT_APPROX. The stats command only
accepts distinct_count_approx, so AGGREGATION_FUNC_MAPPING registers
only that name; the other two are window-only aliases in
WINDOW_FUNC_MAPPING.
The previous predicate required intersection of both maps, which
rejected dc and distinct_count. They fell through to the legacy
RexOver lowering — which is the exact buggy "EnumerableWindow over a
row-fetching scan" shape opensearch-project#5483 was filed against. Fix was incomplete.
Replace the intersection check with: name is in ofWindowFunction AND
its canonical aggregation name (BuiltinFunctionName.name().toLowerCase,
e.g. "distinct_count_approx") is in ofAggregation. Translate the same
way in stripWindowFunctionForAggregate so aggVisitor sees the
registered name. For names already in both maps (count/sum/avg/etc.)
the canonical name equals the user-typed name, so the lookup is a
no-op — no behavior change for the cases that already worked.
ROW_NUMBER still falls through because its canonical name "row_number"
isn't in the aggregation map. Same for percentile / take / first /
last / median / list / values — all rejected by the canonical-name
lookup.
Verified locally:
- eventstats dc(state) → cardinality agg, size:0
- eventstats distinct_count(state) by gender
→ composite over gender + nested cardinality on state, size:0
Regenerated explain_eventstats_dc.json and
explain_eventstats_distinct_count.json with the new shape (composite
size 1000 to match CI). Both tests are pushdown-only
(enabledOnlyWhenPushdownIsEnabled() + loadFromFile hardcoded to
calcite/), so no calcite_no_pushdown/ variants needed.
Signed-off-by: Jialiang Liang <jiallian@amazon.com>1 parent 515f35e commit bb8d9b2
3 files changed
Lines changed: 40 additions & 9 deletions
File tree
- core/src/main/java/org/opensearch/sql/calcite
- integ-test/src/test/resources/expectedOutput/calcite
Lines changed: 36 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
39 | 39 | | |
40 | 40 | | |
41 | 41 | | |
| 42 | + | |
42 | 43 | | |
43 | 44 | | |
44 | 45 | | |
| |||
2246 | 2247 | | |
2247 | 2248 | | |
2248 | 2249 | | |
2249 | | - | |
2250 | | - | |
2251 | | - | |
| 2250 | + | |
| 2251 | + | |
| 2252 | + | |
| 2253 | + | |
| 2254 | + | |
| 2255 | + | |
| 2256 | + | |
| 2257 | + | |
| 2258 | + | |
| 2259 | + | |
| 2260 | + | |
| 2261 | + | |
| 2262 | + | |
2252 | 2263 | | |
2253 | 2264 | | |
2254 | 2265 | | |
| |||
2279 | 2290 | | |
2280 | 2291 | | |
2281 | 2292 | | |
| 2293 | + | |
| 2294 | + | |
| 2295 | + | |
| 2296 | + | |
| 2297 | + | |
| 2298 | + | |
| 2299 | + | |
| 2300 | + | |
| 2301 | + | |
| 2302 | + | |
| 2303 | + | |
| 2304 | + | |
| 2305 | + | |
2282 | 2306 | | |
2283 | 2307 | | |
2284 | 2308 | | |
| |||
2321 | 2345 | | |
2322 | 2346 | | |
2323 | 2347 | | |
| 2348 | + | |
| 2349 | + | |
| 2350 | + | |
| 2351 | + | |
| 2352 | + | |
| 2353 | + | |
| 2354 | + | |
| 2355 | + | |
2324 | 2356 | | |
2325 | 2357 | | |
2326 | 2358 | | |
2327 | 2359 | | |
2328 | | - | |
2329 | | - | |
| 2360 | + | |
2330 | 2361 | | |
2331 | 2362 | | |
2332 | 2363 | | |
| |||
Lines changed: 2 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | | - | |
4 | | - | |
| 3 | + | |
| 4 | + | |
5 | 5 | | |
6 | 6 | | |
Lines changed: 2 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | | - | |
4 | | - | |
| 3 | + | |
| 4 | + | |
5 | 5 | | |
6 | 6 | | |
0 commit comments