[CALCITE-7702] JoinAggregateTransposeRule produces a non-equivalent plan when the aggregate with empty input and empty group set - #5171
Conversation
| ~ limitations under the License. | ||
| --> | ||
| <Root> | ||
| <TestCase name="testNoPullAggregateWithEmptyInputAndEmptyGroupSet"> |
There was a problem hiding this comment.
can you add a quidem test which exhibits the bug? Reading plans is hard.
There was a problem hiding this comment.
Thanks for reviewing. I added a Quidem test to join-agg-transpose.iq. It checks the query result directly. Without the fix, the query returns no rows instead of (0, 10).
| // Pull-up adds group keys and may lose that row. Require the input to be | ||
| // known non-empty. | ||
| && (!left.getGroupSet().isEmpty() | ||
| || Boolean.FALSE.equals(mq.isEmpty(left.getInput()))) |
There was a problem hiding this comment.
I hope that this is conservative in the right direction: it never answers "yes" when it could be empty.
There was a problem hiding this comment.
Yes. mq.isEmpty returns false only when the input is proved to be non-empty. If it is empty or may be empty, the rule does not fire.
|
I will wait a bit to see if @julianhyde is satisfied. |
|
@mihaibudiu, I've not reviewed the PR but my issues with the spec are resolved. |
|
I think you can squash the commits for merging. |
…lan when the aggregate with empty input and empty group set
ab622f8 to
71a12b1
Compare
Thanks. Done. |
|



Jira Link
CALCITE-7702
Changes Proposed
JoinAggregateTransposeRulecan produce a non-equivalent plan when an Aggregate has an empty input and an empty group set. The original Aggregate returns one row, but after pull-up the JOIN columns become group keys and the new Aggregate returns no rows.For an Aggregate with an empty group set, the rule now applies only when metadata proves that its input is non-empty.
A regression test covers this case.