sql: quote a bare map identifier so option values round-trip - #37993
Open
def- wants to merge 1 commit into
Open
Conversation
`parse_option_value` accepts a `MAP[k => v]` literal, and that grammar commits
to the map form on the `MAP` keyword alone and then demands `[`. Expression
position dispatches on a two-token lookahead (`MAP` followed by `[` or `(`) and
otherwise falls through to an identifier, but the option-value grammar has no
such fallback. So an option value named `map` printed bare, which both
`AstDisplay` and the pretty printer did, fails to reparse:
CREATE SINK s FROM t INTO KAFKA CONNECTION c (TOPIC = "map") FORMAT BYTES
ENVELOPE DEBEZIUM
printed `TOPIC = map`, and reparsing that raised "Expected left square bracket,
found right parenthesis". Every generic option value is affected, a
materialized view's `PARTITION BY` among them.
Add `MAP` to `Ident::can_be_printed_bare`'s quoting set, next to `LIST`, which
is there for the analogous `list[1]` re-lex. The change is display-only: nothing
that parsed before stops parsing, identifiers named `map` just print quoted.
The comment claiming `MAP` was safe because `MAP[...]` requires `=>` only
considered expression position, and is corrected.
Found by the cargo-fuzz `sql_roundtrip` target. Adds a regression test beside
the `LIST` one. The keyword-quoting fixtures in `tests/testdata/select`,
`pretty.slt` and `quote_ident.slt` now show `"map"`, which is what
`quote_ident` already returned for `list` and `array`.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
parse_option_valueaccepts aMAP[k => v]literal, and that grammar commits to the map form on theMAPkeyword alone and then demands[. Expression position dispatches on a two-token lookahead (MAPfollowed by[or() and otherwise falls through to an identifier, but the option-value grammar has no such fallback. So an option value namedmapprinted bare, which bothAstDisplayand the pretty printer did, fails to reparse:printed
TOPIC = map, and reparsing that raised "Expected left square bracket, found right parenthesis". Every generic option value is affected, a materialized view'sPARTITION BYamong them.Add
MAPtoIdent::can_be_printed_bare's quoting set, next toLIST, which is there for the analogouslist[1]re-lex. The change is display-only: nothing that parsed before stops parsing, identifiers namedmapjust print quoted. The comment claimingMAPwas safe becauseMAP[...]requires=>only considered expression position, and is corrected.Found by the cargo-fuzz
sql_roundtriptarget. Adds a regression test beside theLISTone. The keyword-quoting fixtures intests/testdata/select,pretty.sltandquote_ident.sltnow show"map", which is whatquote_identalready returned forlistandarray.