[FLINK-39847][table] Support in-place conversion of a table to a materialized table#28287
Open
raminqaf wants to merge 4 commits into
Open
[FLINK-39847][table] Support in-place conversion of a table to a materialized table#28287raminqaf wants to merge 4 commits into
raminqaf wants to merge 4 commits into
Conversation
Collaborator
AHeise
reviewed
Jun 2, 2026
8e9f442 to
62aa1b4
Compare
62aa1b4 to
f8a9683
Compare
AHeise
reviewed
Jun 5, 2026
Contributor
AHeise
left a comment
There was a problem hiding this comment.
LAGTM. We need to figure out if we need a special conversion element.
| catalogModificationListeners.forEach( | ||
| listener -> | ||
| listener.onEvent( | ||
| AlterTableEvent.createEvent( |
Contributor
There was a problem hiding this comment.
I have no idea for what these things are used but I wanted to flag that it might be surprising for whoever consumes this.
…aterialized table conversion Introduce the building blocks for in-place conversion of a regular table to a materialized table. Neither part is wired into SQL execution on its own. Add the cluster-level table.materialized-table.conversion-from-table.enabled option (default false) that gates the conversion. It is read from the root configuration, so a session-level SET has no effect. Add Catalog#convertTableToMaterializedTable, which swaps an existing regular table's catalog entry for a materialized table in place while preserving its identity and storage. The default throws UnsupportedOperationException; GenericInMemoryCatalog overrides it with a table-kind check. CatalogManager resolves both tables, delegates to the catalog, and fires an AlterTableEvent. Launching the refresh job is left to the executor, not the catalog.
…CREATE OR ALTER handleCreateOrAlter now dispatches on the kind of the existing object: a materialized table is altered as before, a view is rejected, and a regular table is converted in place to a materialized table when table.materialized-table.conversion-from-table.enabled is set on the cluster (otherwise the statement is rejected as before). The conversion carries over the source table's watermark and primary key when the DDL omits them, rejecting a source with more than one watermark. It emits the structured TableChanges (columns, constraint, watermark, definition query, options, distribution, start mode) by reusing the shared change-building helpers, and returns a ConvertTableToMaterializedTableOperation.
…materialized table The SQL gateway's MaterializedTableManager now handles ConvertTableToMaterializedTableOperation: it swaps the catalog entry and then launches the refresh job (a continuous streaming job or a full-mode workflow) and persists the refresh handler, mirroring CREATE MATERIALIZED TABLE. Without this the gateway rejected the operation as unsupported, so conversion swapped the catalog entry but never started refreshing. On a refresh-job-launch failure the conversion makes a best-effort rollback: it drops the materialized table and recreates the original regular table from the operation's original table. Unlike CREATE there is no clean reverse path (the catalog only converts table to materialized table, and alterTable rejects kind changes), so this restores the user's prior state rather than dropping the table outright. TestFileSystemCatalog gains the conversion override and the materialized table ITCase base enables the cluster-level conversion flag so the path can be exercised end to end.
f8a9683 to
d422760
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
This is the implementation of the FLIP-578: In-place Table to Materialized Table conversion
Introduce the building blocks for in-place conversion of a regular table to a materialized table use the already existing CoA command.
Brief change log
(for example:)
Add the cluster-level
table.materialized-table.conversion-from-table.enabledoption (defaultfalse) that gates the conversion. It is read from the root configuration, so a session-level SET has no effect.Add
Catalog#convertTableToMaterializedTable, which swaps an existing regular table's catalog entry for a materialized table in place while preserving its identity and storage. The default throwsUnsupportedOperationException;GenericInMemoryCatalogoverrides it with a table-kind check.CatalogManagerresolves both tables, delegates to the catalog, and fires anAlterTableEvent. Launching the refresh job is left to the executor, not the catalog.handleCreateOrAlter now dispatches on the kind of the existing object: a materialized table is altered as before, a view is rejected, and a regular table is converted in place to a materialized table when
table.materialized-table.conversion-from-table.enabledis set on the cluster (otherwise the statement is rejected as before). The conversion carries over the source table's watermark and primary key when the DDL omits them, rejecting a source with more than one watermark. It emits the structured TableChanges (columns, constraint, watermark, definition query, options, distribution, start mode) by reusing the shared change-building helpers, and returns aConvertTableToMaterializedTableOperation.Verifying this change
SqlNodeToOperationConvertTableToMaterializedTableTestMaterializedTableStatementITCaseDoes this pull request potentially affect one of the following parts:
@Public(Evolving): yesDocumentation
Was generative AI tooling used to co-author this PR?
Generated-by: Opus 4.8