lei-jia-xing opened a new pull request, #3063:
URL: https://github.com/apache/datafusion-sqlparser-rs/pull/3063
Closes #3054. Follow-up to #3040.
Previously, `Parser::parse_create` parsed prefix modifiers upfront and only
checked `has_modifier` in three arms (`USER MAPPING`, `FOREIGN TABLE`,`FOREIGN
DATA WRAPPER`), so other targets silently dropped unsupported modifiers (e.g.
`CREATE TEMP POLICY p ON t USING (true);` round-tripped as `CREATE POLICY p ON
t USING (true)`, which PostgreSQL rejects per
<https://www.postgresql.org/docs/17/sql-createpolicy.html>).
This PR replaces `has_modifier` with `CreateModifiers::ensure_empty(target)`:
- Each `CREATE` branch consumes only the modifiers its AST preserves and
rejects any remaining modifier with `"<TARGET> does not accept this modifier"`
at that modifier's location.
- `Dialect::supports_create_or_alter_function` (enabled on `MsSqlDialect`)
ensures non-MSSQL `FUNCTION` branches reject `OR ALTER` instead of dropping it.
- `LOCAL`/`GLOBAL` are parsed once via `parse_one_of_keywords` so `CREATE
LOCAL GLOBAL TABLE` fails instead of dropping `LOCAL`.
Note for reviewers on error message unification:
- Parsing `UNLOGGED` uniformly alongside other modifiers replaces the
pre-`has_modifier` `peek_keywords(&[UNLOGGED, TABLE])` workaround from #2251,
so `CREATE UNLOGGED VIEW` now reports `"CREATE VIEW does not accept this
modifier"` instead of `"Expected: an object type after CREATE, found:
UNLOGGED"`.
- Removing the mid-dispatch `else if or_replace` arm unifies `OR REPLACE`
rejections on targets like `FOREIGN TABLE` to `"CREATE FOREIGN TABLE does not
accept this modifier"` (matching `USER MAPPING`), and unknown targets after `OR
REPLACE` to `"Expected: an object type after CREATE"`.
AI assistance was used to implement the refactor and tests.
--
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]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]