Skip to content

[FLINK-39253][table] Preserve field names in ROW function from AS aliases#27775

Open
autophagy wants to merge 1 commit intoapache:masterfrom
autophagy:FLINK-39253
Open

[FLINK-39253][table] Preserve field names in ROW function from AS aliases#27775
autophagy wants to merge 1 commit intoapache:masterfrom
autophagy:FLINK-39253

Conversation

@autophagy
Copy link
Contributor

@autophagy autophagy commented Mar 16, 2026

What is the purpose of the change

This pull request fixes the ROW function to preserve field names when arguments use AS aliases or field references.

Previously, the ROW function would always generate default field names (f0, f1, f2, etc.) even when users explicitly provided meaningful names through AS expressions or field references, requiring the user of the f columns or casting in things like subsequent where clauses.

The current implementation of row makes the following kinds of expressions impossible:

env.from("example_order_passthrough")
    .select(
        $("order_id"),
        row(
                    $("customer_id").as("customer_id"),
                    $("product_id").as("product_id"),
                    $("price").as("price"))
        .as("details"))
    .where($("details").get("price").isGreaterOrEqual(50))
    .execute()
    .print(); 

as they fail with:

Exception in thread "main" org.apache.flink.table.api.ValidationException: Invalid function call:
get(ROW<`f0` INT, `f1` STRING, `f2` DOUBLE> NOT NULL, CHAR(5) NOT NULL) 

Brief change log

  • Added getArgumentName(int pos) method to the CallContext interface to expose argument names/aliases
  • Implemented name extraction in ResolveCallByArgumentsRule and CallBindingCallContext to extract names from AS expressions and FieldReferenceExpressions.
  • Modified RowTypeStrategy to use extracted argument names when available, falling back to default f{idx} naming when not

Verifying this change

This change added tests and can be verified as follows:

  • Added integration test RowFunctionITCase test case.

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): yes
  • 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? yes
  • If yes, how is the feature documented? JavaDocs

@flinkbot
Copy link
Collaborator

flinkbot commented Mar 16, 2026

CI report:

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

@autophagy autophagy marked this pull request as draft March 16, 2026 13:01
@autophagy autophagy changed the title [FLINK-39253][table] Preserve field names in ROW function from AS aliases and field references [FLINK-39253][table] Preserve field names in ROW function from AS aliases Mar 16, 2026
@autophagy autophagy marked this pull request as ready for review March 16, 2026 18:11

if (arg instanceof CallExpression) {
final CallExpression call = (CallExpression) arg;
if (call.getFunctionDefinition() == BuiltInFunctionDefinitions.AS) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I notice here there is a way of aliasing using = as well as AS. Does Flink support this? If so can we add a unit test to ensure this works in the same way as AS.

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 don't believe Flink does support it, but I'll verify

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