You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@calcite.apache.org by "chloe-zh (via GitHub)" <gi...@apache.org> on 2026/06/04 07:02:27 UTC
[PR] Fix REGR_COUNT arguments being dropped during SqlToRel conversion [calcite]
chloe-zh opened a new pull request, #4990:
URL: https://github.com/apache/calcite/pull/4990
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.
<!--
Thanks for sending a pull request! Here are some critical tips for you:
1. READ THE GUIDE FIRST: https://calcite.apache.org/develop/#contributing
*For significant contributions, please discuss on the dev mailing list or Jira BEFORE coding.*
2. JIRA IS USUALLY MANDATORY: Ensure you have created an issue on the Calcite Jira:
https://issues.apache.org/jira/projects/CALCITE/issues
*Check existing issues first to avoid duplicates.*
*Note: A Jira is NOT required for typos and cosmetic changes (i.e., changes that are neither bugs nor features).*
3. TIMING: Strongly recommended to create the Jira BEFORE you start writing code (e.g., a day or so before posting a PR).
This gives others a chance to weigh in on your specification.
4. CRITICAL CONSISTENCY RULE
The following three items MUST match exactly in wording and meaning:
(A) The Jira Issue Title
(B) This Pull Request Title
(C) Your Git Commit Message
Format: [CALCITE-XXXX] <Description>
Example: [CALCITE-0000] Add IF NOT EXISTS clause to CREATE TABLE
Guidelines for a good Title:
- Illustrate using SQL keywords (in ALL-CAPS) rather than Java method names.
- Focus on the specification and user experience, not the implementation.
- Make it clear whether it is a bug or a feature.
- Use words like "should" to indicate desired behavior vs. current behavior (e.g., "Validator should not close model file").
5. REPRODUCTION: If fixing a bug, please provide a concise SQL example or test case to reproduce the issue for a faster review.
6. TESTING: Ensure `./gradlew build` passes and appropriate tests are added/updated.
-->
## Jira Link
None
## Problem
When parses `REGR_COUNT(y, x)` the SqlKind is mistakenly set to `SqlKind.COUNT` instead of `SqlKind.REGR_COUNT`, the agg builder then drop the args `y` and `x` and 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:
```
REGR_COUNT(y, x) -> REGR_COUNT(*)
```
which is semantically incorrect
## Changes Proposed
<!--
Please clarify what changes you are proposing. The purpose of this section is to outline the changes and how this PR fixes the issue.
If possible, please consider writing useful notes for better and faster reviews in your PR.
-->
- Correct the SqlKind to REGR_COUNT
- At build agg call, check SqlKind instead of `instanceof` thus it always focuses on real count and bypass regr_count
- Remove regr_count from `AggregateReduceFunctionsRule` given it is irreducible.
--
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: commits-unsubscribe@calcite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Fix REGR_COUNT arguments being dropped during SqlToRel conversion [calcite]
Posted by "xiedeyantu (via GitHub)" <gi...@apache.org>.
xiedeyantu commented on PR #4990:
URL: https://github.com/apache/calcite/pull/4990#issuecomment-4620879660
The following three items(Jira Title, PR Title, Commit Message) MUST match exactly in wording and meaning, the title cannot contain the word "fix".
--
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: commits-unsubscribe@calcite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Fix REGR_COUNT arguments being dropped during SqlToRel conversion [calcite]
Posted by "sonarqubecloud[bot] (via GitHub)" <gi...@apache.org>.
sonarqubecloud[bot] commented on PR #4990:
URL: https://github.com/apache/calcite/pull/4990#issuecomment-4623592936
## [](https://sonarcloud.io/dashboard?id=apache_calcite&pullRequest=4990) **Quality Gate passed**
Issues
 [1 New issue](https://sonarcloud.io/project/issues?id=apache_calcite&pullRequest=4990&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
 [0 Accepted issues](https://sonarcloud.io/project/issues?id=apache_calcite&pullRequest=4990&issueStatuses=ACCEPTED)
Measures
 [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache_calcite&pullRequest=4990&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
 [100.0% Coverage on New Code](https://sonarcloud.io/component_measures?id=apache_calcite&pullRequest=4990&metric=new_coverage&view=list)
 [0.0% Duplication on New Code](https://sonarcloud.io/component_measures?id=apache_calcite&pullRequest=4990&metric=new_duplicated_lines_density&view=list)
<!-- sqra-placement-anchor -->
[See analysis details on SonarQube Cloud](https://sonarcloud.io/dashboard?id=apache_calcite&pullRequest=4990)
--
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: commits-unsubscribe@calcite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [CALCITE-7579] REGR_COUNT arguments are dropped in RelNode [calcite]
Posted by "xiedeyantu (via GitHub)" <gi...@apache.org>.
xiedeyantu commented on PR #4990:
URL: https://github.com/apache/calcite/pull/4990#issuecomment-4758181121
Will you continue working on this PR?
--
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: commits-unsubscribe@calcite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Fix REGR_COUNT arguments being dropped during SqlToRel conversion [calcite]
Posted by "xiedeyantu (via GitHub)" <gi...@apache.org>.
xiedeyantu commented on PR #4990:
URL: https://github.com/apache/calcite/pull/4990#issuecomment-4620046462
I have approved your Jira account application. You can now create a Jira and assign it to yourself.
--
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: commits-unsubscribe@calcite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [CALCITE-7579] REGR_COUNT arguments are dropped in RelNode [calcite]
Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #4990:
URL: https://github.com/apache/calcite/pull/4990#issuecomment-5030204046
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.
--
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: commits-unsubscribe@calcite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Fix REGR_COUNT arguments being dropped during SqlToRel conversion [calcite]
Posted by "chloe-zh (via GitHub)" <gi...@apache.org>.
chloe-zh commented on PR #4990:
URL: https://github.com/apache/calcite/pull/4990#issuecomment-4620011134
don't have account yet, just signed it up, waiting for update from the apache maintainer
--
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: commits-unsubscribe@calcite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Fix REGR_COUNT arguments being dropped during SqlToRel conversion [calcite]
Posted by "mihaibudiu (via GitHub)" <gi...@apache.org>.
mihaibudiu commented on PR #4990:
URL: https://github.com/apache/calcite/pull/4990#issuecomment-4619818327
Before submitting a PR please file an issue using https://issues.apache.org/jira
--
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: commits-unsubscribe@calcite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Fix REGR_COUNT arguments being dropped during SqlToRel conversion [calcite]
Posted by "chloe-zh (via GitHub)" <gi...@apache.org>.
chloe-zh commented on PR #4990:
URL: https://github.com/apache/calcite/pull/4990#issuecomment-4620088718
thanks team, updated
--
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: commits-unsubscribe@calcite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] REGR_COUNT arguments are dropped in RelNode [calcite]
Posted by "mihaibudiu (via GitHub)" <gi...@apache.org>.
mihaibudiu commented on PR #4990:
URL: https://github.com/apache/calcite/pull/4990#issuecomment-4626480566
You need to add at least one unit test which would prevent this from happening again in the future.
Ideally the test which motivated you to open the issue in the first place.
The final commit message will have to match the JIRA title exactly, including `[CALCITE-7579]`, please see the other commits.
--
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: commits-unsubscribe@calcite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org