Skip to content

Commit d420001

Browse files
authored
fix: unnest join constraint with alias parsing for BigQuery dialect (#732)
* fix: unnest join constraint with alias parsing for BigQuery dialect * chore: fix failing tests
1 parent 650c53d commit d420001

File tree

3 files changed

+33
-21
lines changed

3 files changed

+33
-21
lines changed

src/parser.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5291,12 +5291,15 @@ impl<'a> Parser<'a> {
52915291
Err(_) => false,
52925292
};
52935293

5294-
let with_offset_alias =
5294+
let with_offset_alias = if with_offset {
52955295
match self.parse_optional_alias(keywords::RESERVED_FOR_COLUMN_ALIAS) {
52965296
Ok(Some(alias)) => Some(alias),
52975297
Ok(None) => None,
52985298
Err(e) => return Err(e),
5299-
};
5299+
}
5300+
} else {
5301+
None
5302+
};
53005303

53015304
Ok(TableFactor::UNNEST {
53025305
alias,

tests/sqlparser_bigquery.rs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,34 @@ fn parse_table_identifiers() {
9494
test_table_ident("abc5.GROUP", vec![Ident::new("abc5"), Ident::new("GROUP")]);
9595
}
9696

97+
#[test]
98+
fn parse_join_constraint_unnest_alias() {
99+
assert_eq!(
100+
only(
101+
bigquery()
102+
.verified_only_select("SELECT * FROM t1 JOIN UNNEST(t1.a) AS f ON c1 = c2")
103+
.from
104+
)
105+
.joins,
106+
vec![Join {
107+
relation: TableFactor::UNNEST {
108+
alias: table_alias("f"),
109+
array_expr: Box::new(Expr::CompoundIdentifier(vec![
110+
Ident::new("t1"),
111+
Ident::new("a")
112+
])),
113+
with_offset: false,
114+
with_offset_alias: None
115+
},
116+
join_operator: JoinOperator::Inner(JoinConstraint::On(Expr::BinaryOp {
117+
left: Box::new(Expr::Identifier("c1".into())),
118+
op: BinaryOperator::Eq,
119+
right: Box::new(Expr::Identifier("c2".into())),
120+
})),
121+
}]
122+
);
123+
}
124+
97125
#[test]
98126
fn parse_trailing_comma() {
99127
for (sql, canonical) in [

tests/sqlparser_common.rs

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3683,25 +3683,6 @@ fn parse_unnest() {
36833683
joins: vec![],
36843684
}],
36853685
);
3686-
// 5. WITH OFFSET and WITH OFFSET Alias
3687-
chk(
3688-
true,
3689-
false,
3690-
true,
3691-
&dialects,
3692-
vec![TableWithJoins {
3693-
relation: TableFactor::UNNEST {
3694-
alias: Some(TableAlias {
3695-
name: Ident::new("numbers"),
3696-
columns: vec![],
3697-
}),
3698-
array_expr: Box::new(Expr::Identifier(Ident::new("expr"))),
3699-
with_offset: false,
3700-
with_offset_alias: Some(Ident::new("with_offset_alias")),
3701-
},
3702-
joins: vec![],
3703-
}],
3704-
);
37053686
}
37063687

37073688
#[test]

0 commit comments

Comments
 (0)