Ramin Gharib created FLINK-39799:
------------------------------------

             Summary: Preserve user-typed query text for materialized table and 
view definitions
                 Key: FLINK-39799
                 URL: https://issues.apache.org/jira/browse/FLINK-39799
             Project: Flink
          Issue Type: Bug
          Components: Table SQL / API
            Reporter: Ramin Gharib


When a {{{}CREATE MATERIALIZED TABLE … AS …{}}}, {{{}ALTER MATERIALIZED TABLE … 
AS …{}}}, or {{CREATE VIEW … AS …}} statement is converted to a catalog object, 
the persisted {{originalQuery}} is currently produced by re-rendering the 
parsed {{SqlNode}} via {{SqlNode#toSqlString()}} (through 
{{{}ConvertContext#toQuotedSqlString{}}}). This normalizes the user's input: 
identifier casing is changed, type aliases are expanded ({{{}int{}}} → 
{{{}INTEGER{}}}), whitespace is reformatted, and quoting style is rewritten.

As a result, {{SHOW CREATE MATERIALIZED TABLE}} / {{SHOW CREATE VIEW}} and 
round-trips through the catalog no longer reflect what the user typed, even 
though the field is named {{{}originalQuery{}}}.
h2. Example

User input:
{code:java}
CREATE MATERIALIZED TABLE mt AS SELECT a, b, cast(c as int) as int_c FROM t1 
WHERE c > 200 {code}
 
 
Currently persisted {{{}originalQuery{}}}:
 
 
{code:java}
SELECT `a`, `b`, CAST(`c` AS INTEGER) AS `int_c` FROM `t1` WHERE `c` > 200{code}
 
 
Desired:
 
{code:java}
SELECT a, b, cast(c as int) as int_c FROM t1 WHERE c > 200{code}
The {{expandedQuery}} field is unchanged; it continues to hold the 
fully-qualified, normalized form used by the planner.
h2. Acceptance criteria
 * {{originalQuery}} on {{CatalogMaterializedTable}} and {{CatalogView}} equals 
the verbatim substring the user typed for the AS-query.
 * {{expandedQuery}} remains the planner-normalized form.
 * {{SHOW CREATE MATERIALIZED TABLE}} / {{SHOW CREATE VIEW}} reflect the user's 
original wording.
 * Existing planner tests are updated where they asserted the normalized form.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to