raminqaf opened a new pull request, #28277:
URL: https://github.com/apache/flink/pull/28277

   ## What is the purpose of the change
   
   `CREATE/ALTER MATERIALIZED TABLE … AS …` and `CREATE VIEW … AS …` currently 
persist `originalQuery` by re-rendering the parsed `SqlNode` via 
`SqlNode#toSqlString()`. This normalizes identifier casing, expands type 
aliases (`int` → `INTEGER`), reflows whitespace, and rewrites quoting, so `SHOW 
CREATE MATERIALIZED TABLE` / `SHOW CREATE VIEW` no longer reflect what the user 
typed.
   
   This PR makes `originalQuery` the verbatim substring of the user's input 
statement, sliced via `SqlParserPos` of the AS-query subtree. `expandedQuery` 
continues to hold the planner-normalized form.
   
   ### Example
   
   Input:
   
   ```sql
   CREATE MATERIALIZED TABLE mt AS
     select a, b, cast(c as int) as int_c from t1 where c > 200
   ```
   
   Before:
   
   ```sql
   SELECT `a`, `b`, CAST(`c` AS INTEGER) AS `int_c`
   FROM `t1`
   WHERE `c` > 200
   ```
   
   after:
   ```sql
   select a, b, cast(c as int) as int_c from t1 where c > 200
   ```
   
   ## Brief Changelog
   
   - Thread original SQL statement text from ParserImpl through 
SqlNodeToOperationConversion.convert(...) into SqlNodeConvertContext.
   - Add ConvertContext#toRawSqlString(SqlNode) returning the substring of the 
original statement matching SqlParserPos. Counterpart to existing 
toQuotedSqlString(SqlNode). Falls back to toQuotedSqlString if raw statement 
text is unavailable.
   - Switch AbstractCreateMaterializedTableConverter#getDerivedOriginalQuery, 
SqlAlterMaterializedTableAsQueryConverter, and 
SqlNodeConvertUtils#toCatalogView (covers CREATE VIEW and ALTER VIEW … AS) to 
the new method.
   - Keep existing SqlNodeToOperationConversion.convert(...) signature as an 
overload that delegates with null raw text for backward compatibility.
   
   ## Verifying this Change
   
   - Unit tests in SqlNodeConvertContextTest for toRawSqlString covering nested 
AS-query nodes, comments inside the query, and statements spanning multiple 
lines.
   - Planner tests in MaterializedTableTest and ViewTest asserting 
originalQuery equals the input substring across mixed casing, type aliases 
(int/varchar), whitespace, and quoting styles. Existing expandedQuery 
assertions retained unchanged.
   - Updated planner tests that previously asserted the normalized form of 
originalQuery.
   - SQL gateway round-trip test: create a materialized table / view with 
mixed-case query, run SHOW CREATE and assert the output preserves user wording.
   
   ## Does this pull request potentially affect one of the following parts:
   
   - Dependencies (does it add or upgrade a dependency): no
   - The public API, i.e., is any changed class annotated with 
@Public(Evolving): no (signature change on SqlNodeToOperationConversion is 
@Internal; backward-compatible overload kept)
   - The serializers: no
   - The runtime per-record code paths (performance sensitive): no
   - Anything that affects deployment or recovery: JobManager (and its 
components), Checkpointing, Kubernetes/Yarn, ZooKeeper: no
   - The S3 file system connector: no
   - Note: catalog entries persisted before this change still hold the 
normalized originalQuery. No migration performed.
   
   ## Documentation
   
   - Does this pull request introduce a new feature? no
   - If yes, how is the feature documented? not applicable
   
   #### Was generative AI tooling used to co-author this PR?
   - [x] Yes - Claude Opus 4.7 to go through the implementation once and check 
for inconsistencies 


-- 
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]

Reply via email to