@@ -3516,3 +3516,87 @@ fn test_alter_session_followed_by_statement() {
35163516 _ => panic ! ( "Unexpected statements: {:?}" , stmts) ,
35173517 }
35183518}
3519+
3520+ #[ test]
3521+ fn test_nested_join_without_parentheses ( ) {
3522+ let query = "SELECT DISTINCT p.product_id FROM orders AS o INNER JOIN customers AS c INNER JOIN products AS p ON p.customer_id = c.customer_id ON c.order_id = o.order_id" ;
3523+ assert_eq ! (
3524+ only(
3525+ snowflake( )
3526+ . verified_only_select_with_canonical( query, "" )
3527+ . from
3528+ )
3529+ . joins,
3530+ vec![ Join {
3531+ relation: TableFactor :: NestedJoin {
3532+ table_with_joins: Box :: new( TableWithJoins {
3533+ relation: TableFactor :: Table {
3534+ name: ObjectName :: from( vec![ Ident :: new( "customers" . to_string( ) ) ] ) ,
3535+ alias: Some ( TableAlias {
3536+ name: Ident {
3537+ value: "c" . to_string( ) ,
3538+ quote_style: None ,
3539+ span: Span :: empty( ) ,
3540+ } ,
3541+ columns: vec![ ] ,
3542+ } ) ,
3543+ args: None ,
3544+ with_hints: vec![ ] ,
3545+ version: None ,
3546+ partitions: vec![ ] ,
3547+ with_ordinality: false ,
3548+ json_path: None ,
3549+ sample: None ,
3550+ index_hints: vec![ ] ,
3551+ } ,
3552+ joins: vec![ Join {
3553+ relation: TableFactor :: Table {
3554+ name: ObjectName :: from( vec![ Ident :: new( "products" . to_string( ) ) ] ) ,
3555+ alias: Some ( TableAlias {
3556+ name: Ident {
3557+ value: "p" . to_string( ) ,
3558+ quote_style: None ,
3559+ span: Span :: empty( ) ,
3560+ } ,
3561+ columns: vec![ ] ,
3562+ } ) ,
3563+ args: None ,
3564+ with_hints: vec![ ] ,
3565+ version: None ,
3566+ partitions: vec![ ] ,
3567+ with_ordinality: false ,
3568+ json_path: None ,
3569+ sample: None ,
3570+ index_hints: vec![ ] ,
3571+ } ,
3572+ global: false ,
3573+ join_operator: JoinOperator :: Inner ( JoinConstraint :: On ( Expr :: BinaryOp {
3574+ left: Box :: new( Expr :: CompoundIdentifier ( vec![
3575+ Ident :: new( "p" . to_string( ) ) ,
3576+ Ident :: new( "customer_id" . to_string( ) )
3577+ ] ) ) ,
3578+ op: BinaryOperator :: Eq ,
3579+ right: Box :: new( Expr :: CompoundIdentifier ( vec![
3580+ Ident :: new( "c" . to_string( ) ) ,
3581+ Ident :: new( "customer_id" . to_string( ) )
3582+ ] ) ) ,
3583+ } ) ) ,
3584+ } ]
3585+ } ) ,
3586+ alias: None
3587+ } ,
3588+ global: false ,
3589+ join_operator: JoinOperator :: Inner ( JoinConstraint :: On ( Expr :: BinaryOp {
3590+ left: Box :: new( Expr :: CompoundIdentifier ( vec![
3591+ Ident :: new( "c" . to_string( ) ) ,
3592+ Ident :: new( "order_id" . to_string( ) )
3593+ ] ) ) ,
3594+ op: BinaryOperator :: Eq ,
3595+ right: Box :: new( Expr :: CompoundIdentifier ( vec![
3596+ Ident :: new( "o" . to_string( ) ) ,
3597+ Ident :: new( "order_id" . to_string( ) )
3598+ ] ) ) ,
3599+ } ) )
3600+ } ] ,
3601+ ) ;
3602+ }
0 commit comments