Skip to content

FLINK-XXXXX: add GROUP BY <int literal>#28381

Open
tisyabhatia wants to merge 1 commit into
apache:masterfrom
tisyabhatia:FLINK-XXXXX-group-by-ordinal
Open

FLINK-XXXXX: add GROUP BY <int literal>#28381
tisyabhatia wants to merge 1 commit into
apache:masterfrom
tisyabhatia:FLINK-XXXXX-group-by-ordinal

Conversation

@tisyabhatia

@tisyabhatia tisyabhatia commented Jun 10, 2026

Copy link
Copy Markdown

What is the purpose of the change

This pull request adds initial support for positional references in the GROUP BY clause (GROUP BY <n>) in Flink SQL. When enabled, an integer literal n in GROUP BY refers to the n-th expression in the SELECT list.

Because this changes the meaning of existing queries, the behavior is gated behind a new table config option that is disabled by default. It is intended to flip to true in a future release after a customer-notice period.

This feature requires no parser / grammar changes as Apache Calcite (apache/calcite) already resolves group ordinals when its SqlConformance.isGroupByOrdinal() returns true. Flink simply enables that resolution per the config flag by wrapping the validator's conformance, so Calcite's ordinal resolution and error handling are reused as-is.

This work is backed by an internal design doc and a FLIP (currently under review).

Brief change log

  • Add table config option table.group-by-ordinal-enabled (default false) gating the behavior
  • Wrap the conformance in FlinkCalciteSqlValidator so isGroupByOrdinal() returns true only when the option is enabled, reusing Calcite's native group-ordinal resolution
  • Add batch SQL execution tests in GroupByOrdinalTest

Verifying this change

This change added tests and can be verified as follows:

  • Batch SQL execution coverage in GroupByOrdinalTest (parametrized: ordinal -> column, multiple ordinals, ordinal mixed with explicit column, ordinal -> whole expression; plus the flag-off "literal stays a constant" case and out-of-range, zero-ordinal, and ordinal-points-at-an-aggregated errors)
  • Verified the feature is gated by the table.group-by-ordinal-enabled config option (off by default preserves existing GROUP BY <constant> semantics)

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

  • Dependencies: no
  • @Public(Evolving) API: no
  • Serializers: no
  • Runtime per-record code paths: no
  • Deployment/recovery (JobManager, Checkpointing, K8s/Yarn, ZK): no
  • S3 file system connector: no

Documentation

  • Introduces a new feature? yes
  • How documented? Not documented in this PR

Was generative AI tooling used to co-author this PR? Yes - Generated-by: Claude Code

@tisyabhatia tisyabhatia marked this pull request as draft June 10, 2026 20:46
@flinkbot

flinkbot commented Jun 10, 2026

Copy link
Copy Markdown
Collaborator

CI report:

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

@tisyabhatia tisyabhatia marked this pull request as ready for review June 11, 2026 19:37
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.

2 participants