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

   ## What is the purpose of the change
   
   Every other DDL object accepts `IF EXISTS` on `ALTER`, but a view does not. 
On `master` both of these are parse errors:
   
   ```
   ALTER VIEW IF EXISTS v RENAME TO v2
   ALTER VIEW IF EXISTS v AS SELECT 1
   -- Encountered "EXISTS" at line 1, column 15
   ```
   
   A SQL script that is safe to re-run for tables therefore still fails as soon 
as it touches a view. This is the smallest of the four object kinds listed in 
the issue; `ALTER DATABASE`, `ALTER CATALOG` and `ALTER MATERIALIZED TABLE` are 
left for follow-ups (CATALOG additionally needs `CatalogManager#alterCatalog` 
to grow the flag).
   
   ## Brief change log
   
   - `parserImpls.ftl`: accept an optional `IF EXISTS` after `ALTER VIEW` and 
pass it to both AST forms.
   - `SqlAlterView` / `SqlAlterViewAs` / `SqlAlterViewRename`: carry the flag, 
keep the old constructors delegating with `false`, and unparse it so 
round-tripping works.
   - `SqlNodeConvertUtils`: add `findAlterView()`; keep `validateAlterView()`'s 
non-null contract, because `SqlAlterViewPropertiesConverter` dereferences the 
returned view, and add `validateAlterViewWithIfExists()` returning `null` only 
when the statement carries the flag.
   - `SqlAlterViewAsConverter` / `SqlAlterViewRenameConverter`: a missing view 
with the flag becomes `NopOperation`, the same mechanism 
`AbstractAlterTableConverter` uses for `ALTER TABLE IF EXISTS`; rename also 
forwards the flag to `Catalog#renameTable`, which already accepts it.
   - `AlterViewAsOperation` / `AlterViewRenameOperation`: forward 
`ignoreIfNotExists` to the catalog.
   
   ## Verifying this change
   
   - `FLINK-41412` parser tests: both forms parse and unparse with the flag; 
the forms without it are unchanged.
   - New `SqlAlterViewIfExistsConverterTest`: with the flag, both statements 
convert to `NopOperation` for a missing view; without the flag they still raise 
`ValidationException`. Verified red on `master`: the test fails with 
`Encountered "EXISTS" at line 1, column 15`, and passes after the change.
   - `./mvnw -pl flink-table/flink-table-planner 
-Dtest='SqlAlterViewIfExistsConverterTest,SqlDdlToOperationConverterTest' test` 
— 80 tests, 0 failures.
   - `./mvnw -pl flink-table/flink-sql-parser -Dtest=FlinkSqlParserImplTest 
test` — 719 tests, 0 failures, 8 skipped.
   - `spotless:check` and `checkstyle:check` pass.
   
   ## Does this pull request potentially affect one of the following parts
   
   - Dependencies: no
   - The public API of `@PublicEvolving` classes: no (the parser AST gains a 
flag; the old constructors are kept)
   - Serializers: no
   - Anything that affects deployment or recovery: no
   
   ## Documentation
   
   - Does this pull request introduce a new feature? It adds `IF EXISTS` to an 
existing DDL statement family, matching `ALTER TABLE IF EXISTS`.
   - If yes, how is the feature documented? It follows the existing `ALTER 
TABLE ... IF EXISTS` docs; I can add a line to the SQL reference if maintainers 
want it.
   
   ---
   
   **AI Disclosure**
   
   Prepared with AI assistance (DeepSeek Harness), which drafted the parser, 
AST, converter and operation changes and the tests. I reviewed the diff and ran 
the commands above locally, including the red run against `master`; the 
direction and the final patch are my own.
   


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