Skip to content

Conversation

lincoln-lil
Copy link
Contributor

What is the purpose of the change

As reported in https://issues.apache.org/jira/browse/CALCITE-7192, the following query may produce wrong result:

SELECT STDDEV_POP(salary) FILTER (WHERE salary > 1000) FROM employees;

the decomposition for STDDEV_POP will be:

SQRT((SUM(x * x) - SUM(x) * SUM(x) / COUNT(x))/ COUNT(x))

for the above example, the SUM(salary * salary) lost the filter salary > 1000. The fix itself is very simple.

Brief change log

Fix AggregateReduceFunctionsRule and add corresponding tests

Verifying this change

Newly added rule test AggregateReduceFunctionsRuleTest

Does this pull request potentially affect one of the following parts:

  • Dependencies (does it add or upgrade a dependency): (no)
  • The public API, i.e., is any changed class annotated with @public(Evolving): (no)
  • The serializers: (no )
  • The runtime per-record code paths (performance sensitive): (no)
  • Anything that affects deployment or recovery: JobManager (and its components), Checkpointing, Kubernetes/Yarn, ZooKeeper: (no)
  • The S3 file system connector: (no)

Documentation

  • Does this pull request introduce a new feature? (no)

@flinkbot
Copy link
Collaborator

flinkbot commented Sep 22, 2025

CI report:

Bot commands The @flinkbot bot supports the following commands:
  • @flinkbot run azure re-run the last Azure build

@snuyanzin
Copy link
Contributor

lgtm, however I would vote first to have it merged in Calcite

@lincoln-lil
Copy link
Contributor Author

@snuyanzin the fix has been merged in Calcite, could you please take another look when you have time?

@lincoln-lil lincoln-lil merged commit a1ec502 into apache:master Sep 26, 2025
@gaborgsomogyi
Copy link
Contributor

Are you guys planning to backport this to 2.1.1 because I'm just about to prepare the release?

@snuyanzin
Copy link
Contributor

it is there #27046
however it should be updated as I mentioned there
not sure if @lincoln-lil has time for this
I can do this later today however then will need a reviewer for that

@gaborgsomogyi
Copy link
Contributor

we're not in a super rush so if this can be done in couple of days then it's fine

@gaborgsomogyi
Copy link
Contributor

if the change is relatively trivial I can jump in as reviewer, just ping me if that's so

@snuyanzin
Copy link
Contributor

@gaborgsomogyi I updated PR #27046 with backport to 2.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants