mihaibudiu commented on PR #5382:
URL: https://github.com/apache/calcite/pull/5382#issuecomment-6958085881
The agent review of this PR claims it has uncovered several bugs too:
- [ ] WITHIN DISTINCT is dropped (wrong result). The rebuild at [lines
133-154](vscode-webview://0vmbcrpjhhem6eq7gmqn097csfrd45p1ipvg3u5fb5nrv7sej7c0/core/src/main/java/org/apache/calcite/rel/rules/AggregateUnionNullBranchRule.java#L133-L154)
copies distinct, filter, sort and other fields of the call, but not
distinctKeys. It also drops the aggregate's hints.
- Query: SUM(d2) WITHIN DISTINCT (deptno) over emp(deptno, deptno*2) UNION
ALL dept(deptno, NULL).
- On scott, the result is 120 without the rule and 620 with it.
- [ ] isPureGroupBy accepts GROUP BY () ([lines
246-250](vscode-webview://0vmbcrpjhhem6eq7gmqn097csfrd45p1ipvg3u5fb5nrv7sej7c0/core/src/main/java/org/apache/calcite/rel/rules/AggregateUnionNullBranchRule.java#L246-L250)).
An Aggregate(group={}) returns 1 row even when its input is empty. The
projection that replaces it returns 0 rows.
- Plan: Project(99, NULL) over Aggregate(group={}) over Filter(EMPNO < 0).
The rule turns this into Project over Filter, and the group with key 99 is lost.
- Risk is low. RelBuilder folds this shape into VALUES, so only
LogicalAggregate.create or plans built with pruneInputOfAggregate=false reach
it.
- Fix: require a non-empty group set.
- [ ] Type narrowing (a weak case). When the removed branch set the union
column type, the rebuilt aggregate runs at the narrower type and then casts the
result.
- A RelBuilder plan that unions SMALLINT with null:BIGINT becomes
SUM(SMALLINT) and fails with "Value 37609 out of range".
- SQL cannot reach this: SqlToRel casts the kept branch, which I checked
for BIGINT. The original RelBuilder plan also fails in Enumerable, with a Short
to Long cast error.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]