Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/main/jjtree/net/sf/jsqlparser/parser/JSqlParserCC.jjt
Original file line number Diff line number Diff line change
Expand Up @@ -2135,6 +2135,13 @@ public class CCJSqlParser extends AbstractJSqlParser<CCJSqlParser> {
return true;
}

// BigQuery SELECT AS STRUCT / AS VALUE IF(...): STRUCT and VALUE can also be plain
// identifiers, so only the IF( function call is accepted after them.
if ((prev.kind == K_STRUCT || prev.kind == K_VALUE)
&& getToken(1).kind == K_IF && getToken(2).kind == OPENING_BRACKET) {
return true;
}

// ── 5. Conservative default: fall back to follower check ──────
return isReservedKeywordSafeByFollower();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,21 @@ void testCreateTableCloneWithOptions() throws JSQLParserException {
}

@Test
void testCloneRemainsUsableAsIdentifier() throws JSQLParserException {
void testCreateTableAsSelectAsStructWithIfFunction() throws JSQLParserException {
String sqlStr = "CREATE OR REPLACE TABLE p.d.t AS\n"
+ "SELECT ARRAY(SELECT AS STRUCT IF(x.l, 'a', 'b') AS label, x.prob AS prob FROM UNNEST(s.arr) x) AS probs\n"
+ "FROM p.d.src s";
TestUtils.assertSqlCanBeParsedAndDeparsed(sqlStr, true);
}

@Test
void testSelectAsValueWithIfFunction() throws JSQLParserException {
String sqlStr = "SELECT ARRAY(SELECT AS VALUE IF(x.l, 'a', 'b') FROM UNNEST(s.arr) x) FROM t s";
TestUtils.assertSqlCanBeParsedAndDeparsed(sqlStr, true);
}

@Test
void testCloneRemainsUsableAsIdentifier()throws JSQLParserException {
String sqlStr = "SELECT clone FROM t";
TestUtils.assertSqlCanBeParsedAndDeparsed(sqlStr, true);
}
Expand Down
Loading