snuyanzin commented on code in PR #27199: URL: https://github.com/apache/flink/pull/27199#discussion_r2532190377
########## docs/content/docs/dev/table/materialized-table/statements.md: ########## @@ -311,6 +335,46 @@ It might happen that types of columns are not the same, in that case implicit ca If for some of the combinations implicit cast is not supported then there will be validation error thrown. Also, it is worth to note that reordering can also be done here. +Create or alter a materialized table executed twice: + +```sql +-- First execution: creates the table +CREATE OR ALTER MATERIALIZED TABLE my_materialized_table + FRESHNESS = INTERVAL '10' SECOND + AS + SELECT + user_id, + COUNT(*) AS event_count, + SUM(amount) AS total_amount + FROM + kafka_catalog.db1.events + WHERE + event_type = 'purchase' + GROUP BY + user_id; + +-- Second execution: alters the query definition (adds avg_amount column) +CREATE OR ALTER MATERIALIZED TABLE my_materialized_table + FRESHNESS = INTERVAL '10' SECOND + AS + SELECT + user_id, + COUNT(*) AS event_count, + SUM(amount) AS total_amount, + AVG(amount) AS avg_amount -- Add a new nullable column at the end + FROM + kafka_catalog.db1.events + WHERE + event_type = 'purchase' + GROUP BY + user_id; +``` + +<span class="label label-danger">Note</span> +- When altering an existing table, schema evolution currently only supports adding `nullable` columns to the end of the original table's schema. Review Comment: ```suggestion - When altering an existing materialized table, schema evolution currently only supports adding `nullable` columns to the end of the original materialized table's schema. ``` -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
