Skip to content

Commit c788526

Browse files
committed
add more cases to test
1 parent 84d074b commit c788526

File tree

1 file changed

+326
-0
lines changed

1 file changed

+326
-0
lines changed

tests/sqlparser_snowflake.rs

Lines changed: 326 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3599,4 +3599,330 @@ fn test_nested_join_without_parentheses() {
35993599
}))
36003600
}],
36013601
);
3602+
3603+
let query = "SELECT DISTINCT p.product_id FROM orders AS o JOIN customers AS c JOIN products AS p ON p.customer_id = c.customer_id ON c.order_id = o.order_id";
3604+
assert_eq!(
3605+
only(
3606+
snowflake()
3607+
.verified_only_select_with_canonical(query, "")
3608+
.from
3609+
)
3610+
.joins,
3611+
vec![Join {
3612+
relation: TableFactor::NestedJoin {
3613+
table_with_joins: Box::new(TableWithJoins {
3614+
relation: TableFactor::Table {
3615+
name: ObjectName::from(vec![Ident::new("customers".to_string())]),
3616+
alias: Some(TableAlias {
3617+
name: Ident {
3618+
value: "c".to_string(),
3619+
quote_style: None,
3620+
span: Span::empty(),
3621+
},
3622+
columns: vec![],
3623+
}),
3624+
args: None,
3625+
with_hints: vec![],
3626+
version: None,
3627+
partitions: vec![],
3628+
with_ordinality: false,
3629+
json_path: None,
3630+
sample: None,
3631+
index_hints: vec![],
3632+
},
3633+
joins: vec![Join {
3634+
relation: TableFactor::Table {
3635+
name: ObjectName::from(vec![Ident::new("products".to_string())]),
3636+
alias: Some(TableAlias {
3637+
name: Ident {
3638+
value: "p".to_string(),
3639+
quote_style: None,
3640+
span: Span::empty(),
3641+
},
3642+
columns: vec![],
3643+
}),
3644+
args: None,
3645+
with_hints: vec![],
3646+
version: None,
3647+
partitions: vec![],
3648+
with_ordinality: false,
3649+
json_path: None,
3650+
sample: None,
3651+
index_hints: vec![],
3652+
},
3653+
global: false,
3654+
join_operator: JoinOperator::Join(JoinConstraint::On(Expr::BinaryOp {
3655+
left: Box::new(Expr::CompoundIdentifier(vec![
3656+
Ident::new("p".to_string()),
3657+
Ident::new("customer_id".to_string())
3658+
])),
3659+
op: BinaryOperator::Eq,
3660+
right: Box::new(Expr::CompoundIdentifier(vec![
3661+
Ident::new("c".to_string()),
3662+
Ident::new("customer_id".to_string())
3663+
])),
3664+
})),
3665+
}]
3666+
}),
3667+
alias: None
3668+
},
3669+
global: false,
3670+
join_operator: JoinOperator::Join(JoinConstraint::On(Expr::BinaryOp {
3671+
left: Box::new(Expr::CompoundIdentifier(vec![
3672+
Ident::new("c".to_string()),
3673+
Ident::new("order_id".to_string())
3674+
])),
3675+
op: BinaryOperator::Eq,
3676+
right: Box::new(Expr::CompoundIdentifier(vec![
3677+
Ident::new("o".to_string()),
3678+
Ident::new("order_id".to_string())
3679+
])),
3680+
}))
3681+
}],
3682+
);
3683+
3684+
let query = "SELECT DISTINCT p.product_id FROM orders AS o LEFT JOIN customers AS c LEFT JOIN products AS p ON p.customer_id = c.customer_id ON c.order_id = o.order_id";
3685+
assert_eq!(
3686+
only(
3687+
snowflake()
3688+
.verified_only_select_with_canonical(query, "")
3689+
.from
3690+
)
3691+
.joins,
3692+
vec![Join {
3693+
relation: TableFactor::NestedJoin {
3694+
table_with_joins: Box::new(TableWithJoins {
3695+
relation: TableFactor::Table {
3696+
name: ObjectName::from(vec![Ident::new("customers".to_string())]),
3697+
alias: Some(TableAlias {
3698+
name: Ident {
3699+
value: "c".to_string(),
3700+
quote_style: None,
3701+
span: Span::empty(),
3702+
},
3703+
columns: vec![],
3704+
}),
3705+
args: None,
3706+
with_hints: vec![],
3707+
version: None,
3708+
partitions: vec![],
3709+
with_ordinality: false,
3710+
json_path: None,
3711+
sample: None,
3712+
index_hints: vec![],
3713+
},
3714+
joins: vec![Join {
3715+
relation: TableFactor::Table {
3716+
name: ObjectName::from(vec![Ident::new("products".to_string())]),
3717+
alias: Some(TableAlias {
3718+
name: Ident {
3719+
value: "p".to_string(),
3720+
quote_style: None,
3721+
span: Span::empty(),
3722+
},
3723+
columns: vec![],
3724+
}),
3725+
args: None,
3726+
with_hints: vec![],
3727+
version: None,
3728+
partitions: vec![],
3729+
with_ordinality: false,
3730+
json_path: None,
3731+
sample: None,
3732+
index_hints: vec![],
3733+
},
3734+
global: false,
3735+
join_operator: JoinOperator::Left(JoinConstraint::On(Expr::BinaryOp {
3736+
left: Box::new(Expr::CompoundIdentifier(vec![
3737+
Ident::new("p".to_string()),
3738+
Ident::new("customer_id".to_string())
3739+
])),
3740+
op: BinaryOperator::Eq,
3741+
right: Box::new(Expr::CompoundIdentifier(vec![
3742+
Ident::new("c".to_string()),
3743+
Ident::new("customer_id".to_string())
3744+
])),
3745+
})),
3746+
}]
3747+
}),
3748+
alias: None
3749+
},
3750+
global: false,
3751+
join_operator: JoinOperator::Left(JoinConstraint::On(Expr::BinaryOp {
3752+
left: Box::new(Expr::CompoundIdentifier(vec![
3753+
Ident::new("c".to_string()),
3754+
Ident::new("order_id".to_string())
3755+
])),
3756+
op: BinaryOperator::Eq,
3757+
right: Box::new(Expr::CompoundIdentifier(vec![
3758+
Ident::new("o".to_string()),
3759+
Ident::new("order_id".to_string())
3760+
])),
3761+
}))
3762+
}],
3763+
);
3764+
3765+
let query = "SELECT DISTINCT p.product_id FROM orders AS o RIGHT JOIN customers AS c RIGHT JOIN products AS p ON p.customer_id = c.customer_id ON c.order_id = o.order_id";
3766+
assert_eq!(
3767+
only(
3768+
snowflake()
3769+
.verified_only_select_with_canonical(query, "")
3770+
.from
3771+
)
3772+
.joins,
3773+
vec![Join {
3774+
relation: TableFactor::NestedJoin {
3775+
table_with_joins: Box::new(TableWithJoins {
3776+
relation: TableFactor::Table {
3777+
name: ObjectName::from(vec![Ident::new("customers".to_string())]),
3778+
alias: Some(TableAlias {
3779+
name: Ident {
3780+
value: "c".to_string(),
3781+
quote_style: None,
3782+
span: Span::empty(),
3783+
},
3784+
columns: vec![],
3785+
}),
3786+
args: None,
3787+
with_hints: vec![],
3788+
version: None,
3789+
partitions: vec![],
3790+
with_ordinality: false,
3791+
json_path: None,
3792+
sample: None,
3793+
index_hints: vec![],
3794+
},
3795+
joins: vec![Join {
3796+
relation: TableFactor::Table {
3797+
name: ObjectName::from(vec![Ident::new("products".to_string())]),
3798+
alias: Some(TableAlias {
3799+
name: Ident {
3800+
value: "p".to_string(),
3801+
quote_style: None,
3802+
span: Span::empty(),
3803+
},
3804+
columns: vec![],
3805+
}),
3806+
args: None,
3807+
with_hints: vec![],
3808+
version: None,
3809+
partitions: vec![],
3810+
with_ordinality: false,
3811+
json_path: None,
3812+
sample: None,
3813+
index_hints: vec![],
3814+
},
3815+
global: false,
3816+
join_operator: JoinOperator::Right(JoinConstraint::On(Expr::BinaryOp {
3817+
left: Box::new(Expr::CompoundIdentifier(vec![
3818+
Ident::new("p".to_string()),
3819+
Ident::new("customer_id".to_string())
3820+
])),
3821+
op: BinaryOperator::Eq,
3822+
right: Box::new(Expr::CompoundIdentifier(vec![
3823+
Ident::new("c".to_string()),
3824+
Ident::new("customer_id".to_string())
3825+
])),
3826+
})),
3827+
}]
3828+
}),
3829+
alias: None
3830+
},
3831+
global: false,
3832+
join_operator: JoinOperator::Right(JoinConstraint::On(Expr::BinaryOp {
3833+
left: Box::new(Expr::CompoundIdentifier(vec![
3834+
Ident::new("c".to_string()),
3835+
Ident::new("order_id".to_string())
3836+
])),
3837+
op: BinaryOperator::Eq,
3838+
right: Box::new(Expr::CompoundIdentifier(vec![
3839+
Ident::new("o".to_string()),
3840+
Ident::new("order_id".to_string())
3841+
])),
3842+
}))
3843+
}],
3844+
);
3845+
3846+
let query = "SELECT DISTINCT p.product_id FROM orders AS o FULL JOIN customers AS c FULL JOIN products AS p ON p.customer_id = c.customer_id ON c.order_id = o.order_id";
3847+
assert_eq!(
3848+
only(
3849+
snowflake()
3850+
.verified_only_select_with_canonical(query, "")
3851+
.from
3852+
)
3853+
.joins,
3854+
vec![Join {
3855+
relation: TableFactor::NestedJoin {
3856+
table_with_joins: Box::new(TableWithJoins {
3857+
relation: TableFactor::Table {
3858+
name: ObjectName::from(vec![Ident::new("customers".to_string())]),
3859+
alias: Some(TableAlias {
3860+
name: Ident {
3861+
value: "c".to_string(),
3862+
quote_style: None,
3863+
span: Span::empty(),
3864+
},
3865+
columns: vec![],
3866+
}),
3867+
args: None,
3868+
with_hints: vec![],
3869+
version: None,
3870+
partitions: vec![],
3871+
with_ordinality: false,
3872+
json_path: None,
3873+
sample: None,
3874+
index_hints: vec![],
3875+
},
3876+
joins: vec![Join {
3877+
relation: TableFactor::Table {
3878+
name: ObjectName::from(vec![Ident::new("products".to_string())]),
3879+
alias: Some(TableAlias {
3880+
name: Ident {
3881+
value: "p".to_string(),
3882+
quote_style: None,
3883+
span: Span::empty(),
3884+
},
3885+
columns: vec![],
3886+
}),
3887+
args: None,
3888+
with_hints: vec![],
3889+
version: None,
3890+
partitions: vec![],
3891+
with_ordinality: false,
3892+
json_path: None,
3893+
sample: None,
3894+
index_hints: vec![],
3895+
},
3896+
global: false,
3897+
join_operator: JoinOperator::FullOuter(JoinConstraint::On(
3898+
Expr::BinaryOp {
3899+
left: Box::new(Expr::CompoundIdentifier(vec![
3900+
Ident::new("p".to_string()),
3901+
Ident::new("customer_id".to_string())
3902+
])),
3903+
op: BinaryOperator::Eq,
3904+
right: Box::new(Expr::CompoundIdentifier(vec![
3905+
Ident::new("c".to_string()),
3906+
Ident::new("customer_id".to_string())
3907+
])),
3908+
}
3909+
)),
3910+
}]
3911+
}),
3912+
alias: None
3913+
},
3914+
global: false,
3915+
join_operator: JoinOperator::FullOuter(JoinConstraint::On(Expr::BinaryOp {
3916+
left: Box::new(Expr::CompoundIdentifier(vec![
3917+
Ident::new("c".to_string()),
3918+
Ident::new("order_id".to_string())
3919+
])),
3920+
op: BinaryOperator::Eq,
3921+
right: Box::new(Expr::CompoundIdentifier(vec![
3922+
Ident::new("o".to_string()),
3923+
Ident::new("order_id".to_string())
3924+
])),
3925+
}))
3926+
}],
3927+
);
36023928
}

0 commit comments

Comments
 (0)