Skip to content

Commit 4c135f4

Browse files
committed
Cargo fmt
1 parent cf272e7 commit 4c135f4

4 files changed

Lines changed: 99 additions & 75 deletions

File tree

src/ast/query.rs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1120,15 +1120,20 @@ pub enum ConnectByKind {
11201120
impl fmt::Display for ConnectByKind {
11211121
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
11221122
match self {
1123-
ConnectByKind::ConnectBy { relationships, nocycle } => {
1124-
write!(f, "CONNECT BY {nocycle}{relationships}",
1123+
ConnectByKind::ConnectBy {
1124+
relationships,
1125+
nocycle,
1126+
} => {
1127+
write!(
1128+
f,
1129+
"CONNECT BY {nocycle}{relationships}",
11251130
nocycle = if *nocycle { "NOCYCLE " } else { "" },
11261131
relationships = display_comma_separated(relationships)
11271132
)
1128-
},
1133+
}
11291134
ConnectByKind::StartWith(condition) => {
11301135
write!(f, "START WITH {condition}")
1131-
},
1136+
}
11321137
}
11331138
}
11341139
}

src/ast/spans.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2283,9 +2283,10 @@ impl Spanned for Select {
22832283
impl Spanned for ConnectByKind {
22842284
fn span(&self) -> Span {
22852285
match self {
2286-
ConnectByKind::ConnectBy { relationships, nocycle: _ } => {
2287-
union_spans(relationships.iter().map(|item| item.span()))
2288-
}
2286+
ConnectByKind::ConnectBy {
2287+
relationships,
2288+
nocycle: _,
2289+
} => union_spans(relationships.iter().map(|item| item.span())),
22892290
ConnectByKind::StartWith(expr) => expr.span(),
22902291
}
22912292
}

src/parser/mod.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14185,7 +14185,10 @@ impl<'a> Parser<'a> {
1418514185
let relationships = self.with_state(ParserState::ConnectBy, |parser| {
1418614186
parser.parse_comma_separated(Parser::parse_expr)
1418714187
})?;
14188-
clauses.push(ConnectByKind::ConnectBy { relationships, nocycle });
14188+
clauses.push(ConnectByKind::ConnectBy {
14189+
relationships,
14190+
nocycle,
14191+
});
1418914192
} else {
1419014193
break;
1419114194
}

tests/sqlparser_common.rs

Lines changed: 82 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -12637,55 +12637,62 @@ fn parse_connect_by() {
1263712637
"ORDER BY employee_id"
1263812638
);
1263912639

12640-
assert_eq!(dialects.verified_only_select(connect_by_1), Select {
12641-
select_token: AttachedToken::empty(),
12642-
optimizer_hint: None,
12643-
distinct: None,
12644-
top: None,
12645-
top_before_distinct: false,
12646-
projection: vec![
12647-
SelectItem::UnnamedExpr(Expr::Identifier(Ident::new("employee_id"))),
12648-
SelectItem::UnnamedExpr(Expr::Identifier(Ident::new("manager_id"))),
12649-
SelectItem::UnnamedExpr(Expr::Identifier(Ident::new("title"))),
12650-
],
12651-
exclude: None,
12652-
from: vec![TableWithJoins {
12653-
relation: table_from_name(ObjectName::from(vec![Ident::new("employees")])),
12654-
joins: vec![],
12655-
}],
12656-
into: None,
12657-
lateral_views: vec![],
12658-
prewhere: None,
12659-
selection: None,
12660-
group_by: GroupByExpr::Expressions(vec![], vec![]),
12661-
cluster_by: vec![],
12662-
distribute_by: vec![],
12663-
sort_by: vec![],
12664-
having: None,
12665-
named_window: vec![],
12666-
qualify: None,
12667-
window_before_qualify: false,
12668-
value_table_mode: None,
12669-
connect_by: vec![
12670-
ConnectByKind::StartWith(Expr::BinaryOp {
12671-
left: Box::new(Expr::Identifier(Ident::new("title"))),
12672-
op: BinaryOperator::Eq,
12673-
right: Box::new(Expr::Value(
12674-
Value::SingleQuotedString("president".to_owned()).with_empty_span(),
12675-
)),
12676-
}.into()),
12677-
ConnectByKind::ConnectBy {
12678-
relationships: vec![Expr::BinaryOp {
12679-
left: Box::new(Expr::Identifier(Ident::new("manager_id"))),
12680-
op: BinaryOperator::Eq,
12681-
right: Box::new(Expr::Prior(Box::new(Expr::Identifier(Ident::new(
12682-
"employee_id",
12683-
))))),
12684-
}],
12685-
nocycle: false,
12640+
assert_eq!(
12641+
dialects.verified_only_select(connect_by_1),
12642+
Select {
12643+
select_token: AttachedToken::empty(),
12644+
optimizer_hint: None,
12645+
distinct: None,
12646+
top: None,
12647+
top_before_distinct: false,
12648+
projection: vec![
12649+
SelectItem::UnnamedExpr(Expr::Identifier(Ident::new("employee_id"))),
12650+
SelectItem::UnnamedExpr(Expr::Identifier(Ident::new("manager_id"))),
12651+
SelectItem::UnnamedExpr(Expr::Identifier(Ident::new("title"))),
12652+
],
12653+
exclude: None,
12654+
from: vec![TableWithJoins {
12655+
relation: table_from_name(ObjectName::from(vec![Ident::new("employees")])),
12656+
joins: vec![],
1268612657
}],
12687-
flavor: SelectFlavor::Standard,
12688-
});
12658+
into: None,
12659+
lateral_views: vec![],
12660+
prewhere: None,
12661+
selection: None,
12662+
group_by: GroupByExpr::Expressions(vec![], vec![]),
12663+
cluster_by: vec![],
12664+
distribute_by: vec![],
12665+
sort_by: vec![],
12666+
having: None,
12667+
named_window: vec![],
12668+
qualify: None,
12669+
window_before_qualify: false,
12670+
value_table_mode: None,
12671+
connect_by: vec![
12672+
ConnectByKind::StartWith(
12673+
Expr::BinaryOp {
12674+
left: Box::new(Expr::Identifier(Ident::new("title"))),
12675+
op: BinaryOperator::Eq,
12676+
right: Box::new(Expr::Value(
12677+
Value::SingleQuotedString("president".to_owned()).with_empty_span(),
12678+
)),
12679+
}
12680+
.into()
12681+
),
12682+
ConnectByKind::ConnectBy {
12683+
relationships: vec![Expr::BinaryOp {
12684+
left: Box::new(Expr::Identifier(Ident::new("manager_id"))),
12685+
op: BinaryOperator::Eq,
12686+
right: Box::new(Expr::Prior(Box::new(Expr::Identifier(Ident::new(
12687+
"employee_id",
12688+
))))),
12689+
}],
12690+
nocycle: false,
12691+
}
12692+
],
12693+
flavor: SelectFlavor::Standard,
12694+
}
12695+
);
1268912696

1269012697
// CONNECT BY can come before START WITH
1269112698
let connect_by_2 = concat!(
@@ -12736,13 +12743,17 @@ fn parse_connect_by() {
1273612743
}],
1273712744
nocycle: false,
1273812745
},
12739-
ConnectByKind::StartWith(Expr::BinaryOp {
12740-
left: Box::new(Expr::Identifier(Ident::new("title"))),
12741-
op: BinaryOperator::Eq,
12742-
right: Box::new(Expr::Value(
12743-
Value::SingleQuotedString("president".to_owned()).with_empty_span(),
12744-
)),
12745-
}.into())],
12746+
ConnectByKind::StartWith(
12747+
Expr::BinaryOp {
12748+
left: Box::new(Expr::Identifier(Ident::new("title"))),
12749+
op: BinaryOperator::Eq,
12750+
right: Box::new(Expr::Value(
12751+
Value::SingleQuotedString("president".to_owned()).with_empty_span(),
12752+
)),
12753+
}
12754+
.into()
12755+
)
12756+
],
1274612757
flavor: SelectFlavor::Standard,
1274712758
}
1274812759
);
@@ -12791,13 +12802,16 @@ fn parse_connect_by() {
1279112802
window_before_qualify: false,
1279212803
value_table_mode: None,
1279312804
connect_by: vec![
12794-
ConnectByKind::StartWith(Expr::BinaryOp {
12805+
ConnectByKind::StartWith(
12806+
Expr::BinaryOp {
1279512807
left: Box::new(Expr::Identifier(Ident::new("title"))),
1279612808
op: BinaryOperator::Eq,
1279712809
right: Box::new(Expr::Value(
1279812810
(Value::SingleQuotedString("president".to_owned(),)).with_empty_span()
1279912811
)),
12800-
}.into()),
12812+
}
12813+
.into()
12814+
),
1280112815
ConnectByKind::ConnectBy {
1280212816
relationships: vec![Expr::BinaryOp {
1280312817
left: Box::new(Expr::Identifier(Ident::new("manager_id"))),
@@ -12807,7 +12821,8 @@ fn parse_connect_by() {
1280712821
))))),
1280812822
}],
1280912823
nocycle: false,
12810-
}],
12824+
}
12825+
],
1281112826
flavor: SelectFlavor::Standard,
1281212827
}
1281312828
);
@@ -12866,15 +12881,14 @@ fn parse_connect_by() {
1286612881
qualify: None,
1286712882
window_before_qualify: false,
1286812883
value_table_mode: None,
12869-
connect_by: vec![
12870-
ConnectByKind::ConnectBy {
12871-
relationships: vec![Expr::BinaryOp {
12872-
left: Expr::Identifier(Ident::new("parent")).into(),
12873-
op: BinaryOperator::Eq,
12874-
right: Expr::Prior(Expr::Identifier(Ident::new("child")).into()).into(),
12875-
}],
12876-
nocycle: true,
12884+
connect_by: vec![ConnectByKind::ConnectBy {
12885+
relationships: vec![Expr::BinaryOp {
12886+
left: Expr::Identifier(Ident::new("parent")).into(),
12887+
op: BinaryOperator::Eq,
12888+
right: Expr::Prior(Expr::Identifier(Ident::new("child")).into()).into(),
1287712889
}],
12890+
nocycle: true,
12891+
}],
1287812892
flavor: SelectFlavor::Standard,
1287912893
}
1288012894
);
@@ -12885,7 +12899,8 @@ fn parse_connect_by() {
1288512899
"SELECT 0 FROM t WHERE 1 = 1 START WITH 'a' = 'a' CONNECT BY 2 = 2 GROUP BY 3",
1288612900
);
1288712901
dialects.verified_only_select(
12888-
"SELECT 0 FROM t WHERE 1 = 1 CONNECT BY 2 = 2 START WITH 'a' = 'a' GROUP BY 3");
12902+
"SELECT 0 FROM t WHERE 1 = 1 CONNECT BY 2 = 2 START WITH 'a' = 'a' GROUP BY 3",
12903+
);
1288912904
}
1289012905

1289112906
#[test]

0 commit comments

Comments
 (0)