Skip to content

Commit c2da87d

Browse files
authored
Revert "Allow plain JOIN without turning it into INNER (apache#1692)"
This reverts commit 5b4c7ae.
1 parent 7ba1252 commit c2da87d

File tree

8 files changed

+16
-42
lines changed

8 files changed

+16
-42
lines changed

src/ast/query.rs

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2038,16 +2038,9 @@ impl fmt::Display for Join {
20382038
}
20392039

20402040
match &self.join_operator {
2041-
JoinOperator::Join(constraint) => write!(
2042-
f,
2043-
" {}JOIN {}{}",
2044-
prefix(constraint),
2045-
self.relation,
2046-
suffix(constraint)
2047-
),
20482041
JoinOperator::Inner(constraint) => write!(
20492042
f,
2050-
" {}INNER JOIN {}{}",
2043+
" {}JOIN {}{}",
20512044
prefix(constraint),
20522045
self.relation,
20532046
suffix(constraint)
@@ -2135,7 +2128,6 @@ impl fmt::Display for Join {
21352128
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
21362129
#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
21372130
pub enum JoinOperator {
2138-
Join(JoinConstraint),
21392131
Inner(JoinConstraint),
21402132
LeftOuter(JoinConstraint),
21412133
RightOuter(JoinConstraint),

src/ast/spans.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2001,7 +2001,6 @@ impl Spanned for Join {
20012001
impl Spanned for JoinOperator {
20022002
fn span(&self) -> Span {
20032003
match self {
2004-
JoinOperator::Join(join_constraint) => join_constraint.span(),
20052004
JoinOperator::Inner(join_constraint) => join_constraint.span(),
20062005
JoinOperator::LeftOuter(join_constraint) => join_constraint.span(),
20072006
JoinOperator::RightOuter(join_constraint) => join_constraint.span(),

src/parser/mod.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11000,13 +11000,9 @@ impl<'a> Parser<'a> {
1100011000

1100111001
let join_operator_type = match peek_keyword {
1100211002
Keyword::INNER | Keyword::JOIN => {
11003-
let inner = self.parse_keyword(Keyword::INNER); // [ INNER ]
11003+
let _ = self.parse_keyword(Keyword::INNER); // [ INNER ]
1100411004
self.expect_keyword_is(Keyword::JOIN)?;
11005-
if inner {
11006-
JoinOperator::Inner
11007-
} else {
11008-
JoinOperator::Join
11009-
}
11005+
JoinOperator::Inner
1101011006
}
1101111007
kw @ Keyword::LEFT | kw @ Keyword::RIGHT => {
1101211008
let _ = self.next_token(); // consume LEFT/RIGHT

src/test_utils.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,7 @@ pub fn join(relation: TableFactor) -> Join {
403403
Join {
404404
relation,
405405
global: false,
406-
join_operator: JoinOperator::Join(JoinConstraint::Natural),
406+
join_operator: JoinOperator::Inner(JoinConstraint::Natural),
407407
}
408408
}
409409

tests/sqlparser_bigquery.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1602,7 +1602,7 @@ fn parse_join_constraint_unnest_alias() {
16021602
with_ordinality: false,
16031603
},
16041604
global: false,
1605-
join_operator: JoinOperator::Join(JoinConstraint::On(Expr::BinaryOp {
1605+
join_operator: JoinOperator::Inner(JoinConstraint::On(Expr::BinaryOp {
16061606
left: Box::new(Expr::Identifier("c1".into())),
16071607
op: BinaryOperator::Eq,
16081608
right: Box::new(Expr::Identifier("c2".into())),

tests/sqlparser_common.rs

Lines changed: 9 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -6457,15 +6457,15 @@ fn parse_implicit_join() {
64576457
joins: vec![Join {
64586458
relation: table_from_name(ObjectName::from(vec!["t1b".into()])),
64596459
global: false,
6460-
join_operator: JoinOperator::Join(JoinConstraint::Natural),
6460+
join_operator: JoinOperator::Inner(JoinConstraint::Natural),
64616461
}],
64626462
},
64636463
TableWithJoins {
64646464
relation: table_from_name(ObjectName::from(vec!["t2a".into()])),
64656465
joins: vec![Join {
64666466
relation: table_from_name(ObjectName::from(vec!["t2b".into()])),
64676467
global: false,
6468-
join_operator: JoinOperator::Join(JoinConstraint::Natural),
6468+
join_operator: JoinOperator::Inner(JoinConstraint::Natural),
64696469
}],
64706470
},
64716471
],
@@ -6523,7 +6523,7 @@ fn parse_joins_on() {
65236523
"t2",
65246524
table_alias("foo"),
65256525
false,
6526-
JoinOperator::Join,
6526+
JoinOperator::Inner,
65276527
)]
65286528
);
65296529
one_statement_parses_to(
@@ -6533,7 +6533,7 @@ fn parse_joins_on() {
65336533
// Test parsing of different join operators
65346534
assert_eq!(
65356535
only(&verified_only_select("SELECT * FROM t1 JOIN t2 ON c1 = c2").from).joins,
6536-
vec![join_with_constraint("t2", None, false, JoinOperator::Join)]
6536+
vec![join_with_constraint("t2", None, false, JoinOperator::Inner)]
65376537
);
65386538
assert_eq!(
65396539
only(&verified_only_select("SELECT * FROM t1 LEFT JOIN t2 ON c1 = c2").from).joins,
@@ -6650,7 +6650,7 @@ fn parse_joins_using() {
66506650
vec![join_with_constraint(
66516651
"t2",
66526652
table_alias("foo"),
6653-
JoinOperator::Join,
6653+
JoinOperator::Inner,
66546654
)]
66556655
);
66566656
one_statement_parses_to(
@@ -6660,10 +6660,6 @@ fn parse_joins_using() {
66606660
// Test parsing of different join operators
66616661
assert_eq!(
66626662
only(&verified_only_select("SELECT * FROM t1 JOIN t2 USING(c1)").from).joins,
6663-
vec![join_with_constraint("t2", None, JoinOperator::Join)]
6664-
);
6665-
assert_eq!(
6666-
only(&verified_only_select("SELECT * FROM t1 INNER JOIN t2 USING(c1)").from).joins,
66676663
vec![join_with_constraint("t2", None, JoinOperator::Inner)]
66686664
);
66696665
assert_eq!(
@@ -6726,14 +6722,9 @@ fn parse_natural_join() {
67266722
}
67276723
}
67286724

6729-
// unspecified join
6725+
// if not specified, inner join as default
67306726
assert_eq!(
67316727
only(&verified_only_select("SELECT * FROM t1 NATURAL JOIN t2").from).joins,
6732-
vec![natural_join(JoinOperator::Join, None)]
6733-
);
6734-
// inner join explicitly
6735-
assert_eq!(
6736-
only(&verified_only_select("SELECT * FROM t1 NATURAL INNER JOIN t2").from).joins,
67376728
vec![natural_join(JoinOperator::Inner, None)]
67386729
);
67396730
// left join explicitly
@@ -6757,7 +6748,7 @@ fn parse_natural_join() {
67576748
// natural join another table with alias
67586749
assert_eq!(
67596750
only(&verified_only_select("SELECT * FROM t1 NATURAL JOIN t2 AS t3").from).joins,
6760-
vec![natural_join(JoinOperator::Join, table_alias("t3"))]
6751+
vec![natural_join(JoinOperator::Inner, table_alias("t3"))]
67616752
);
67626753

67636754
let sql = "SELECT * FROM t1 natural";
@@ -6824,13 +6815,9 @@ fn parse_join_nesting() {
68246815

68256816
#[test]
68266817
fn parse_join_syntax_variants() {
6827-
one_statement_parses_to(
6828-
"SELECT c1 FROM t1 JOIN t2 USING(c1)",
6829-
"SELECT c1 FROM t1 JOIN t2 USING(c1)",
6830-
);
68316818
one_statement_parses_to(
68326819
"SELECT c1 FROM t1 INNER JOIN t2 USING(c1)",
6833-
"SELECT c1 FROM t1 INNER JOIN t2 USING(c1)",
6820+
"SELECT c1 FROM t1 JOIN t2 USING(c1)",
68346821
);
68356822
one_statement_parses_to(
68366823
"SELECT c1 FROM t1 LEFT OUTER JOIN t2 USING(c1)",
@@ -6994,7 +6981,7 @@ fn parse_derived_tables() {
69946981
joins: vec![Join {
69956982
relation: table_from_name(ObjectName::from(vec!["t2".into()])),
69966983
global: false,
6997-
join_operator: JoinOperator::Join(JoinConstraint::Natural),
6984+
join_operator: JoinOperator::Inner(JoinConstraint::Natural),
69986985
}],
69996986
}),
70006987
alias: None,

tests/sqlparser_mysql.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2055,7 +2055,7 @@ fn parse_update_with_joins() {
20552055
index_hints: vec![],
20562056
},
20572057
global: false,
2058-
join_operator: JoinOperator::Join(JoinConstraint::On(Expr::BinaryOp {
2058+
join_operator: JoinOperator::Inner(JoinConstraint::On(Expr::BinaryOp {
20592059
left: Box::new(Expr::CompoundIdentifier(vec![
20602060
Ident::new("o"),
20612061
Ident::new("customer_id")

tests/sqlparser_postgres.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4371,7 +4371,7 @@ fn parse_join_constraint_unnest_alias() {
43714371
with_ordinality: false,
43724372
},
43734373
global: false,
4374-
join_operator: JoinOperator::Join(JoinConstraint::On(Expr::BinaryOp {
4374+
join_operator: JoinOperator::Inner(JoinConstraint::On(Expr::BinaryOp {
43754375
left: Box::new(Expr::Identifier("c1".into())),
43764376
op: BinaryOperator::Eq,
43774377
right: Box::new(Expr::Identifier("c2".into())),

0 commit comments

Comments
 (0)