[
https://issues.apache.org/jira/browse/FLINK-41611?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Timo Theusner updated FLINK-41611:
----------------------------------
Description:
{{CREATE OR ALTER}} and {{ALTER ... AS}} accept a query that inserts a column
and reorders existing ones: {{SELECT a, b, c}} → {{SELECT a, x, c, b}} stores
{{(a, c, b, x)}} while the positional refresh writes {{(a, x, c, b)}}, so
values land in wrong columns. {{validateAndExtractColumnChanges}} compares
positions on different scales, and {{validateChanges}} checks each change
alone. FLIP-492 and FLIP-546 allow only appending at the end.
Proposed Changes
* Rank only persisted columns in
{{MaterializedTableSchemaUtils#validateAndExtractColumnChanges}}, with and
without a column list, so the emitted changes always produce the query's column
order
* Replace the per-change check in
{{AlterMaterializedTableChangeOperation#validateChanges}} with one rule: the
old persisted columns lead the new ones, in their old order
* Keep the rule in {{validateChanges}} only; the emitted changes stay exact for
every query, including ones the rule rejects
* Keep the existing "Column mismatch at position N" message
* Remove the executor projection that wrote refresh results by column name
was:
When CREATE OR ALTER MATERIALIZED TABLE declares a column list and the new
query reorders columns or adds one mid-list, the stored schema keeps its order
and appends new columns at the end. The refresh statements map the query's
columns by position (INSERT INTO t <query>, INSERT OVERWRITE t SELECT * FROM
(<query>)), so values land in the wrong columns, silently for same-typed
columns. The refresh job should map the query's columns to the table's
persisted columns by name.
Proposed Changes
- Project the persisted columns in table order in
DefaultMaterializedTableExecutor#getInsertStatement: INSERT INTO t SELECT
<columns> FROM (<query>)
- Replace SELECT * with the same projection in
DefaultMaterializedTableExecutor#getRefreshStatement
> Allow only appending columns at the end when a materialized table's query
> changes
> ---------------------------------------------------------------------------------
>
> Key: FLINK-41611
> URL: https://issues.apache.org/jira/browse/FLINK-41611
> Project: Flink
> Issue Type: Bug
> Components: Table SQL / Planner
> Reporter: Timo Theusner
> Assignee: Timo Theusner
> Priority: Major
> Labels: pull-request-available
>
> {{CREATE OR ALTER}} and {{ALTER ... AS}} accept a query that inserts a column
> and reorders existing ones: {{SELECT a, b, c}} → {{SELECT a, x, c, b}} stores
> {{(a, c, b, x)}} while the positional refresh writes {{(a, x, c, b)}}, so
> values land in wrong columns. {{validateAndExtractColumnChanges}} compares
> positions on different scales, and {{validateChanges}} checks each change
> alone. FLIP-492 and FLIP-546 allow only appending at the end.
> Proposed Changes
> * Rank only persisted columns in
> {{MaterializedTableSchemaUtils#validateAndExtractColumnChanges}}, with and
> without a column list, so the emitted changes always produce the query's
> column order
> * Replace the per-change check in
> {{AlterMaterializedTableChangeOperation#validateChanges}} with one rule: the
> old persisted columns lead the new ones, in their old order
> * Keep the rule in {{validateChanges}} only; the emitted changes stay exact
> for every query, including ones the rule rejects
> * Keep the existing "Column mismatch at position N" message
> * Remove the executor projection that wrote refresh results by column name
--
This message was sent by Atlassian Jira
(v10.3.26#10030026)