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?

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.

3 participants