When SUM data type derivation is more complex, e.g.:
The rule AggregateExpandDistinctAggregatesRule creates the top aggregate calls with invalid type for not distinct calls.
e.g. SELECT SUM(comm), SUM(DISTINCT comm) FROM emp
Please take a look at the reproducer in the PR.
Proposed fix: infer type of top aggregates by input row type. Pass null type to the call method AggregateCall#create.