JamesIsHuang opened a new pull request, #61061: URL: https://github.com/apache/doris/pull/61061
## Proposed changes Issue: https://github.com/apache/doris/issues/60879 Implement `ANSI_QUOTES` SQL mode support in the Nereids parser. When enabled via `SET sql_mode = 'ANSI_QUOTES'`, double-quoted strings (`"identifier"`) are treated as identifiers instead of string literals, matching standard SQL and MySQL behavior. ### Changes - **DorisLexer.g4**: Add `isAnsiQuotes` flag and `DOUBLE_QUOTED_IDENTIFIER` lexer token with semantic predicate; gate the double-quote alternative in `STRING_LITERAL` with `!isAnsiQuotes` - **DorisParser.g4**: Add `DOUBLE_QUOTED_IDENTIFIER` as an alternative in the `quotedIdentifier` parser rule - **NereidsParser.java**: Pass `isAnsiQuotes` flag from `SqlModeHelper` to the lexer in both `scan()` and `parseAllTokens()` - **PostProcessor.java**: Handle `DOUBLE_QUOTED_IDENTIFIER` token in `exitQuotedIdentifier()` — strip surrounding double quotes and unescape `""` to `"` - **SqlModeHelper.java**: Add `hasAnsiQuotes()` helper method - **NereidsParserTest.java**: Add unit tests for ANSI_QUOTES on/off behavior ### How it works 1. User sets `SET sql_mode = 'ANSI_QUOTES';` 2. `SqlModeHelper.hasAnsiQuotes()` returns `true` 3. `NereidsParser` sets `lexer.isAnsiQuotes = true` 4. Lexer matches `"col_name"` as `DOUBLE_QUOTED_IDENTIFIER` instead of `STRING_LITERAL` 5. Parser treats it as a `quotedIdentifier` (same as backtick-quoted) 6. `PostProcessor` strips quotes and unescapes `""` -> `"` ### Behavior | SQL Mode | `"hello"` parsed as | `'hello'` parsed as | `` `hello` `` parsed as | |---|---|---|---| | Default | String literal | String literal | Identifier | | ANSI_QUOTES | **Identifier** | String literal | Identifier | ## Checklist - [x] Does it affect the results of queries? No (only changes how double quotes are interpreted based on sql_mode) - [x] Have you added test cases? Yes -- 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]
