[FLINK-40496][table-planner] Apply append-only column rules consistently when altering a materialized table - #29034
Open
AHeise wants to merge 1 commit into
Open
Conversation
Collaborator
AHeise
force-pushed
the
FLINK-40496-coa-mt-column-position
branch
2 times, most recently
from
August 28, 2026 13:00
f49fb94 to
bdac042
Compare
AHeise
marked this pull request as ready for review
August 28, 2026 13:01
AHeise
marked this pull request as draft
August 28, 2026 13:02
AHeise
force-pushed
the
FLINK-40496-coa-mt-column-position
branch
3 times, most recently
from
August 28, 2026 14:44
446af6c to
0831111
Compare
AHeise
marked this pull request as ready for review
August 28, 2026 16:06
AHeise
marked this pull request as draft
August 31, 2026 20:48
AHeise
force-pushed
the
FLINK-40496-coa-mt-column-position
branch
from
September 1, 2026 10:06
0831111 to
07a6c29
Compare
AHeise
force-pushed
the
FLINK-40496-coa-mt-column-position
branch
2 times, most recently
from
September 1, 2026 13:46
85c03d2 to
9167191
Compare
…tly when altering a materialized table CREATE OR ALTER derived its column changes from a different diff implementation than ALTER ... AS and did not surface a query-driven column reorder to the append-only validation, so reordering existing columns behaved inconsistently: it was silently applied when the query text was unchanged - rewriting the stored column order with no error - and rejected otherwise. The silent path left the stored schema disagreeing with the query, which then miscompiled the positional refresh INSERT. Route both statements through one diff (validateAndExtractColumnChanges, dropping buildSchemaTableChanges), computing the CREATE OR ALTER diff from the query the same way ALTER ... AS does and positioning old columns by their rank among the columns that survive into the new schema so retained non-persisted columns do not skew it. Apply the append-only rules to every query-carrying alter regardless of whether the query text changed, so reordering or retyping existing columns is rejected consistently; a query-inferred nullability change is treated directionally - a tightening flip such as STRING to STRING NOT NULL is tolerated as an inference artifact while a loosening flip from NOT NULL to nullable renders as a physical column type change and is rejected. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
AHeise
marked this pull request as ready for review
September 1, 2026 15:40
AHeise
force-pushed
the
FLINK-40496-coa-mt-column-position
branch
from
September 1, 2026 15:45
9167191 to
745323d
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What is the purpose of the change
CREATE OR ALTER MATERIALIZED TABLEderived its column changes differently fromALTER ... ASand did not surface a query-driven column reorder to the append-only validation, so reordering existing columns behaved inconsistently: silently applied when the query text was unchanged (rewriting the stored column order with no error), rejected otherwise. The silent path left the stored schema disagreeing with the query and miscompiled the positional refreshINSERT.Given
users_shops = (user_id, shop_id, ds, order_cnt):The bare column list reorders the columns but the query text is unchanged, so no
ModifyDefinitionQueryis produced and the append-only check is skipped — before this change the reorder was applied silently.Brief change log
CREATE OR ALTERcomputes its column diff from the query (viavalidateAndExtractColumnChanges), positioning old columns by their rank among the columns that survive into the new schema so retained non-persisted columns do not skew the diff.CREATE OR ALTERandALTER ... AS): existing columns may not be reordered or retyped even when the query text is unchanged. Metadata-only DDL alters are unaffected.ALTER ... ASandCREATE OR ALTERnow share one diff implementation;buildSchemaTableChangesis removed.Verifying this change
Added and updated tests:
MaterializedTableStatementITCase—CREATE OR ALTERandALTER ... ASreject reordering existing columns end-to-end, including a bare-list reorder with an unchanged query.SqlMaterializedTableNodeToOperationConverterTest,SqlNodeToOperationSqlCreateOrAlterMaterializedTableConverterTest,AlterMaterializedTableAsQueryOperationValidationTest,ValidateAndExtractColumnChangesTest— operation- and guard-level coverage of the reject/accept cases.Does this pull request potentially affect one of the following parts:
@Public(Evolving): noDocumentation
Was generative AI tooling used to co-author this PR?
Generated-by: Claude Code (Claude Opus 4.8)