Timo Theusner created FLINK-41678:
-------------------------------------
Summary: Store a materialized table's query in the table's column
order
Key: FLINK-41678
URL: https://issues.apache.org/jira/browse/FLINK-41678
Project: Flink
Issue Type: Bug
Components: Table SQL / Planner
Reporter: Timo Theusner
A names-only column list in a different order than the query, e.g. {{CREATE
MATERIALIZED TABLE t (b, a) AS SELECT a, b FROM src}}, stores the table as
{{(b, a)}} but keeps the query unchanged. The refresh INSERT is positional, so
{{b}} receives {{a}}'s values and vice versa. {{alignQuery}} reorders the query
operation, but the stored expanded query is not aligned. FLIP-550 requires this
reorder to work as in CTAS.
Proposed Changes
* Rewrite the query's SELECT list into the table's persisted column order, as
{{SqlRewriterUtils}} does for INSERT with a column list, and store its expanded
text
* Apply it on CREATE, CREATE OR ALTER, ALTER ... AS and conversion in
{{MaterializedTableOperationFactory}}
* Apply it to schema-only alters that move any persisted column, by parsing and
rewriting the stored expanded query
* Run it independently of {{validateChanges}}, so the stored query matches
every table that is built
* Reject a query with an ordinal {{ORDER BY}} when a rewrite is needed, since
the ordinal would point at another column
--
This message was sent by Atlassian Jira
(v10.3.26#10030026)