Skip to content

Commit ecaed29

Browse files
committed
databricks/generic: CROSS JOIN with constraints
1 parent fcfaab0 commit ecaed29

File tree

4 files changed

+15
-6
lines changed

4 files changed

+15
-6
lines changed

src/ast/query.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1150,7 +1150,9 @@ impl fmt::Display for Join {
11501150
self.relation,
11511151
suffix(constraint)
11521152
),
1153-
JoinOperator::CrossJoin => write!(f, " CROSS JOIN {}", self.relation),
1153+
JoinOperator::CrossJoin(constraint) => {
1154+
write!(f, " CROSS JOIN {}{}", self.relation, suffix(constraint))
1155+
}
11541156
JoinOperator::LeftSemi(constraint) => write!(
11551157
f,
11561158
" {}LEFT SEMI JOIN {}{}",
@@ -1194,7 +1196,7 @@ pub enum JoinOperator {
11941196
LeftOuter(JoinConstraint),
11951197
RightOuter(JoinConstraint),
11961198
FullOuter(JoinConstraint),
1197-
CrossJoin,
1199+
CrossJoin(JoinConstraint),
11981200
/// LEFT SEMI (non-standard)
11991201
LeftSemi(JoinConstraint),
12001202
/// RIGHT SEMI (non-standard)

src/parser/mod.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7205,13 +7205,15 @@ impl<'a> Parser<'a> {
72057205
JoinOperator::CrossJoin
72067206
} else if self.parse_keyword(Keyword::APPLY) {
72077207
// MSSQL extension, similar to CROSS JOIN LATERAL
7208-
JoinOperator::CrossApply
7208+
|_| JoinOperator::CrossApply
72097209
} else {
72107210
return self.expected("JOIN or APPLY after CROSS", self.peek_token());
72117211
};
7212+
let relation = self.parse_table_factor()?;
7213+
let join_constraint = self.parse_join_constraint(false)?;
72127214
Join {
7213-
relation: self.parse_table_factor()?,
7214-
join_operator,
7215+
relation,
7216+
join_operator: join_operator(join_constraint),
72157217
}
72167218
} else if self.parse_keyword(Keyword::OUTER) {
72177219
// MSSQL extension, similar to LEFT JOIN LATERAL .. ON 1=1

tests/sqlparser_common.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4962,7 +4962,7 @@ fn parse_cross_join() {
49624962
version: None,
49634963
partitions: vec![],
49644964
},
4965-
join_operator: JoinOperator::CrossJoin,
4965+
join_operator: JoinOperator::CrossJoin(JoinConstraint::None),
49664966
},
49674967
only(only(select.from).joins),
49684968
);

tests/sqlparser_databricks.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,3 +227,8 @@ fn test_array_struct_access() {
227227
databricks()
228228
.verified_stmt("SELECT id, extra_questions[0].label AS question, FROM AS detailed_survey");
229229
}
230+
231+
#[test]
232+
fn test_cross_join() {
233+
databricks_and_generic().verified_stmt("SELECT * FROM tbl CROSS JOIN tbl2 ON tbl.id = tbl2.id");
234+
}

0 commit comments

Comments
 (0)