Skip to content

[FLINK-39221][table] Add AGGREGATE_VALUES rule for constant folding o…#27742

Merged
fapaul merged 1 commit intoapache:masterfrom
fapaul:flink-39221
Mar 6, 2026
Merged

[FLINK-39221][table] Add AGGREGATE_VALUES rule for constant folding o…#27742
fapaul merged 1 commit intoapache:masterfrom
fapaul:flink-39221

Conversation

@fapaul
Copy link
Contributor

@fapaul fapaul commented Mar 6, 2026

…f global aggregates

What is the purpose of the change

Add CoreRules.AGGREGATE_VALUES to PRUNE_EMPTY_RULES so the planner can replace a global aggregate over statically empty input (e.g. WHERE 1=0) with literal default Values at plan time (COUNT(*)=0, SUM=null, etc.), eliminating the GroupAggregate node entirely.

Brief change log

  • Enable new planner rule CoreRules.AGGREGATE_VALUES
  • Add plan test to verify constant folding is applied to empty aggregates

Verifying this change

  • New plan test

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

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

Documentation

  • Does this pull request introduce a new feature? (yes / no)
  • If yes, how is the feature documented? (not applicable / docs / JavaDocs / not documented)

@flinkbot
Copy link
Collaborator

flinkbot commented Mar 6, 2026

CI report:

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

Copy link
Contributor

@twalthr twalthr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR @fapaul. I left one last comment.

// Replaces global Aggregate over empty Values with default literal values
// (e.g. COUNT(*)=0). Handles the plan-time case where the planner can
// statically determine the input is empty.
CoreRules.AGGREGATE_VALUES
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we also add this to FlinkBatchRuleSets for unified behavior?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I updated the PR with the batch tests

…f global aggregates

Add CoreRules.AGGREGATE_VALUES to PRUNE_EMPTY_RULES so the planner can
replace a global aggregate over statically empty input (e.g. WHERE 1=0)
with literal default Values at plan time (COUNT(*)=0, SUM=null, etc.),
eliminating the GroupAggregate node entirely.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@fapaul fapaul requested a review from twalthr March 6, 2026 11:15
Copy link
Contributor

@twalthr twalthr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks @fapaul.

@fapaul fapaul merged commit abf53fb into apache:master Mar 6, 2026
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