Skip to content

[FLINK-41363][table] Support IF NOT EXISTS when adding columns with ALTER TABLE - #29808

Open
junmuz wants to merge 2 commits into
apache:masterfrom
junmuz:FLINK-41363-add-column
Open

junmuz wants to merge 2 commits into
apache:masterfrom
junmuz:FLINK-41363-add-column

Conversation

@junmuz

@junmuz junmuz commented Nov 6, 2026 •

Copy link
Copy Markdown

…a ALTER TABLE

What is the purpose of the change

Adds IF NOT EXISTS support when adding columns with ALTER TABLE, allowing schema setup statements to be repeated before an INSERT without failing on existing columns.

Existing columns retain their definitions and positions. For column lists, each existing column is skipped independently while missing columns are added.

Brief change log

  • Support ADD COLUMN IF NOT EXISTS, ADD IF NOT EXISTS column_definition, and ADD IF NOT EXISTS (column_definition, ...).
  • Preserve the conditional addition flag in SQL node reconstruction and unparsing.
  • Filter existing columns before converting schema changes and return a no-op operation when all specified columns already exist.
  • Document the supported syntax, repeatable schema setup, and interaction with ALTER TABLE IF EXISTS.

Verifying this change

This change adds the following test coverage:

  • FlinkSqlParserImplTest: supported syntax, unparsing, quoted identifiers, column definitions, and rejection of unsupported guarded lists.
  • SqlAlterTableAddColumnConverterTest: adding missing columns, preserving existing columns, mixed column lists, no-op behavior, and validation failures.
  • CatalogITCase: repeated CREATE TABLE IF NOT EXISTS and conditional column additions across separate table environments sharing a catalog, followed by successful inserts.
  • SQL Gateway table.q: repeated conditional additions and verification that existing column types, comments, and positions are preserved.

Tests were not run while preparing this PR description, and I will be relying on the CI tests. Manually verified that ALTER TABLE commands work as expected.

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? yes
  • If yes, how is the feature documented? docs — the SQL ALTER TABLE reference includes updated syntax, examples, and behavior for existing columns and missing tables.

Was generative AI tooling used to co-author this PR?
  • Yes (please specify the tool below)

Generated-by: Codex (GPT-6)

@flinkbot

flinkbot commented Nov 6, 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

@junmuz

junmuz commented Nov 7, 2026

Copy link
Copy Markdown
Author

@flinkbot run azure

@junmuz junmuz closed this Nov 7, 2026
@junmuz junmuz reopened this Nov 7, 2026
@junmuz

junmuz commented Nov 9, 2026

Copy link
Copy Markdown
Author

@flinkbot run azure

@junmuz
junmuz force-pushed the FLINK-41363-add-column branch from 729fd3b to 5943e41 Compare November 11, 2026 10:58
@junmuz
junmuz force-pushed the FLINK-41363-add-column branch from 5943e41 to 542ef64 Compare November 11, 2026 17:58
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