[CALCITE-7579] REGR_COUNT arguments are dropped in RelNode#4990
[CALCITE-7579] REGR_COUNT arguments are dropped in RelNode#4990chloe-zh wants to merge 1 commit into
Conversation
REGR_COUNT(y, x) was incorrectly converted to REGR_COUNT(*) because SqlRegrCountAggFunction extends SqlCountAggFunction, which: 1. Hardcodes SqlKind.COUNT in its constructor, causing REGR_COUNT to report the wrong SqlKind. 2. Causes RexBuilder.addAggCall() to match REGR_COUNT via SqlKind.COUNT and strip non-nullable arguments (an optimization valid only for COUNT). 3. Masked a missing case handler in AggregateReduceFunctionsRule, since SqlKind.COUNT is not in functionsToReduce. Fix: - Add a protected constructor to SqlCountAggFunction that accepts SqlKind, allowing subclasses to specify their own kind. - Update SqlRegrCountAggFunction to pass SqlKind.REGR_COUNT. - Guard the nullable-args optimization in RexBuilder.addAggCall() to check SqlKind == COUNT instead of instanceof. - Add case REGR_COUNT in AggregateReduceFunctionsRule to preserve it as-is, since it is irreducible.
|
Before submitting a PR please file an issue using https://issues.apache.org/jira |
|
don't have account yet, just signed it up, waiting for update from the apache maintainer @mihaibudiu |
|
I have approved your Jira account application. You can now create a Jira and assign it to yourself. |
|
thanks team, updated |
|
The following three items(Jira Title, PR Title, Commit Message) MUST match exactly in wording and meaning, the title cannot contain the word "fix". |
|
|
You need to add at least one unit test which would prevent this from happening again in the future. |
|
Will you continue working on this PR? |
|
This pull request has been marked as stale due to 30 days of inactivity. It will be closed in 90 days if no further activity occurs. If you think that’s incorrect or this pull request requires a review, please simply write any comment. If closed, you can revive the PR at any time and @mention a reviewer or discuss it on the dev@calcite.apache.org list. Thank you for your contributions. |



REGR_COUNT(y, x) was incorrectly converted to REGR_COUNT(*) because SqlRegrCountAggFunction extends SqlCountAggFunction, which:
Fix:
Jira Link
https://issues.apache.org/jira/browse/CALCITE-7579
Problem
When parses
REGR_COUNT(y, x)the SqlKind is mistakenly set toSqlKind.COUNTinstead ofSqlKind.REGR_COUNT, the agg builder then drop the argsyandxand replace with*, leading to empty arg list of the agg call at RelNode stage.A way to repro it is, parse and plan it, then convert it back to SQL, it would be:
which is semantically incorrect
Changes Proposed
instanceofthus it always focuses on real count and bypass regr_countAggregateReduceFunctionsRulegiven it is irreducible.