Aleksandr Efimov created IMPALA-15698:
-----------------------------------------
Summary: Calcite planner: preserve grand totals during empty-input
pruning
Key: IMPALA-15698
URL: https://issues.apache.org/jira/browse/IMPALA-15698
Project: IMPALA
Issue Type: Bug
Components: Frontend
Reporter: Aleksandr Efimov
Assignee: Aleksandr Efimov
Calcite removes a mixed grouping-set aggregate when its input is statically
empty, even though the empty grouping set must produce a grand-total row.
{code:sql}
SELECT a, count(*) n, count(v) nv, sum(v) s
FROM (SELECT cast(1 AS int) a, cast(5 AS bigint) v
UNION ALL SELECT 2, 7) t
WHERE 1=0
GROUP BY GROUPING SETS ((a), ());
{code}
Expected: one row (NULL, 0, 0, NULL).
At the logical optimizer stage, the aggregate is replaced by empty
LogicalValues. PruneEmptyRules.AGGREGATE_INSTANCE checks the overall
grouping-key count and misses the empty member of getGroupSets(). Aggregates
containing an empty grouping set must survive this pruning; keyed-only
aggregates should still be pruned.
This report covers the logical pruning step. Native execution of empty grouping
sets also needs separate fixes in shared aggregation planning.
Reproduced on master 234bd0001e33.
--
This message was sent by Atlassian Jira
(v10.3.26#10030026)