Skip to content

sql-parser: only start a map literal when a bracket follows MAP - #37973

Open
def- wants to merge 1 commit into
mainfrom
def/fuzz-03-sql-parser
Open

sql-parser: only start a map literal when a bracket follows MAP#37973
def- wants to merge 1 commit into
mainfrom
def/fuzz-03-sql-parser

Conversation

@def-

@def- def- commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

parse_option_map committed on the MAP keyword alone and then demanded
[, so a bare map in an option-value position was a hard parse error
rather than falling through to the item name it is.

map is a legal bare identifier everywhere else — SELECT "map" prints
as SELECT map and reparses fine — so AstDisplay prints an option whose
value is the item name map unquoted, and that output failed to reparse:

CREATE SINK s FROM t INTO KAFKA CONNECTION c (TOPIC CONFIG = "map")

prints TOPIC CONFIG = map and then fails with "Expected left square
bracket, found right parenthesis".

Look ahead for the bracket instead. The alternative, quoting map in
can_be_printed_bare, would change the printed form of every map
identifier in every position to work around one non-backtracking call
site; the sibling branches of parse_option_value all backtrack already.

Found by the sql_roundtrip cargo-fuzz target.

@def-
def- marked this pull request as ready for review July 31, 2026 09:58
@def-
def- requested a review from a team as a code owner July 31, 2026 09:58
@def-
def- changed the base branch from def/fuzz-02-avro to main July 31, 2026 10:05
@def-
def- requested review from a team as code owners July 31, 2026 10:05
`parse_option_map` committed on the `MAP` keyword alone and then demanded
`[`, so a bare `map` in an option-value position was a hard parse error
rather than falling through to the item name it is.

`map` is a legal bare identifier everywhere else — `SELECT "map"` prints
as `SELECT map` and reparses fine — so `AstDisplay` prints an option whose
value is the item name `map` unquoted, and that output failed to reparse:

    CREATE SINK s FROM t INTO KAFKA CONNECTION c (TOPIC CONFIG = "map")

prints `TOPIC CONFIG = map` and then fails with "Expected left square
bracket, found right parenthesis".

Look ahead for the bracket instead. The alternative, quoting `map` in
`can_be_printed_bare`, would change the printed form of every `map`
identifier in every position to work around one non-backtracking call
site; the sibling branches of `parse_option_value` all backtrack already.

Found by the sql_roundtrip cargo-fuzz target.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant