Zoltán Borók-Nagy created IMPALA-15663:
------------------------------------------
Summary: Calcite: grouped avg() over only NULL inputs returns 0
instead of NULL when it feeds a UNION ALL of a different type
Key: IMPALA-15663
URL: https://issues.apache.org/jira/browse/IMPALA-15663
Project: IMPALA
Issue Type: Bug
Components: Frontend
Reporter: Zoltán Borók-Nagy
With PLANNER=CALCITE, a grouped avg() whose group has only NULL inputs returns
0 instead of NULL when the aggregation is a UNION ALL branch whose other branch
has a different type. The original planner returns NULL.
Repro on TPC-DS SF3000 data, where customer 7611940 has a NULL c_birth_year
(any customer row with a NULL c_birth_year should do):
{code:sql}
select * from (
select c_birth_month m, avg(cast(c_birth_year as decimal(12,2))) a
from customer where c_customer_sk = 7611940 group by c_birth_month
union all select 99, 1.5) t
order by 1;
{code}
{noformat}
PLANNER=ORIGINAL: 8 NULL 99 1.500000
PLANNER=CALCITE: 8 0.000000 99 1.500000
{noformat}
Variants that return the correct NULL with both planners:
* the same aggregate without GROUP BY (also for sum() and max());
* a second branch that is also an avg() over customer, i.e. of the same type.
Found through TPC-DS q18, whose result differs in one group (Arkansas County)
under PLANNER=CALCITE. It reproduces on master 9a6a6b1432: at TPC-DS SF10000, a
build without changes returns the same wrong 0 in q18 with PLANNER=CALCITE,
where the original planner returns NULL.
--
This message was sent by Atlassian Jira
(v10.3.26#10030026)