Skip to content

fix: allow if after a struct keyword - #2960

Merged
manticore-projects merged 3 commits into
JSQLParser:masterfrom
harryfoster2006:fix/bigquery-parse-fail-select-struct-as-if
Nov 26, 2026
Merged

manticore-projects merged 3 commits into
JSQLParser:masterfrom
harryfoster2006:fix/bigquery-parse-fail-select-struct-as-if

Conversation

@harryfoster2006

Copy link
Copy Markdown
Contributor

BigQuery's IF() function failed to parse as the first select item after SELECT AS STRUCT or SELECT AS VALUE:

CREATE OR REPLACE TABLE p.d.t AS
SELECT ARRAY(SELECT AS STRUCT IF(x.l, 'a', 'b') AS label, x.prob AS prob
             FROM UNNEST(s.arr) x) AS probs
FROM p.d.src s

This failed with ParseException: Encountered: , at line 2, column 31, the position of IF.

Cause

IF is a reserved word. isReservedKeywordAsIdentifier() accepts it as a name unconditionally after structural keywords such as DISTINCT, which is why SELECT DISTINCT IF(...) already worked. STRUCT and VALUE are not in that list, so the check fell through to the follower-based rule, which rejects IF (.

Fix

Add a narrow rule to isReservedKeywordAsIdentifier(): IF followed by ( is accepted right after STRUCT or VALUE.

STRUCT and VALUE are deliberately not added to the unconditional keyword list. They are also valid column names, so a following keyword such as LIMIT could otherwise be misread as an alias.

@manticore-projects
manticore-projects merged commit e716d5b into JSQLParser:master Nov 26, 2026
10 checks passed
@manticore-projects

Copy link
Copy Markdown
Contributor

Thank you!

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.

2 participants