You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
GROUP BY on a SELECT alias groups by a non-existent field and returns zero rows with HTTP 200 #296
Grouping by a column's SELECT alias produces an Elasticsearch terms aggregation on a field that does not exist. Validation passes, Elasticsearch answers HTTP 200 with zero buckets, and the caller sees an empty result for a query that should return every group.
Reproduction
SELECT country AS pays FROM bi_events GROUP BY pays -- 0 rows, HTTP 200SELECT country AS pays FROM bi_events GROUP BY country -- correct
Mechanism
Select.fieldAliases is keyed identifierName -> alias, so an alias written in a GROUP BY never reverse-resolves. The bucket is built from the bare name, emitting terms { field: "pays" }. SingleSearch.validate() passes because the bucket's display name coincidentally equals the field's alias.
SELECT country AS pays, COUNT(*) AS cnt FROM t GROUP BY pays
(pays, pays, pays) — the aggregate-bearing twin, wrong too
SELECT UPPER(country) AS c FROM t GROUP BY c
(c, c, c) — wrong for an expression alias
Impact
Three statements in the captured BI corpus (Tableau and Superset) use this spelling. It is a silent wrong answer in the #205 / #207 / #209 / #224 / #253 family — the worst variety, since an empty success looks like "no matching data".
Resolution
A bare-name bucket resolves against the SELECT list's aliases at the AST level before the terms aggregation is built, so GROUP BY pays produces byte-identically the bucket GROUP BY country produces. A projected column always wins over an alias spelled the same. Expression aliases resolve to the aliased expression.
Fixing the resolution also required repairing two things it desynchronised: the terms order for ORDER BY <alias>, and the terms include/exclude for HAVING <alias> — both of which had been silently dropped.
Activity