@@ -12506,6 +12506,92 @@ fn parse_create_table_with_bit_types() {
1250612506 }
1250712507}
1250812508
12509+ #[ test]
12510+ fn parse_composed_access_expr ( ) {
12511+ assert_eq ! (
12512+ verified_expr( "f(a).b" ) ,
12513+ Expr :: CompositeAccess {
12514+ expr: Box :: new( Expr :: Function ( Function {
12515+ name: ObjectName ( vec![ Ident :: new( "f" ) ] ) ,
12516+ uses_odbc_syntax: false ,
12517+ parameters: FunctionArguments :: None ,
12518+ args: FunctionArguments :: List ( FunctionArgumentList {
12519+ duplicate_treatment: None ,
12520+ args: vec![ FunctionArg :: Unnamed ( FunctionArgExpr :: Expr (
12521+ Expr :: Identifier ( Ident :: new( "a" ) )
12522+ ) ) ] ,
12523+ clauses: vec![ ] ,
12524+ } ) ,
12525+ null_treatment: None ,
12526+ filter: None ,
12527+ over: None ,
12528+ within_group: vec![ ]
12529+ } ) ) ,
12530+ key: Ident :: new( "b" )
12531+ }
12532+ ) ;
12533+
12534+ // Nested Composite Access
12535+ assert_eq ! (
12536+ verified_expr( "f(a).b.c" ) ,
12537+ Expr :: CompositeAccess {
12538+ expr: Box :: new( Expr :: CompositeAccess {
12539+ expr: Box :: new( Expr :: Function ( Function {
12540+ name: ObjectName ( vec![ Ident :: new( "f" ) ] ) ,
12541+ uses_odbc_syntax: false ,
12542+ parameters: FunctionArguments :: None ,
12543+ args: FunctionArguments :: List ( FunctionArgumentList {
12544+ duplicate_treatment: None ,
12545+ args: vec![ FunctionArg :: Unnamed ( FunctionArgExpr :: Expr (
12546+ Expr :: Identifier ( Ident :: new( "a" ) )
12547+ ) ) ] ,
12548+ clauses: vec![ ] ,
12549+ } ) ,
12550+ null_treatment: None ,
12551+ filter: None ,
12552+ over: None ,
12553+ within_group: vec![ ]
12554+ } ) ) ,
12555+ key: Ident :: new( "b" )
12556+ } ) ,
12557+ key: Ident :: new( "c" )
12558+ }
12559+ ) ;
12560+
12561+ // Composite Access in Select and Where Clauses
12562+ let stmt = verified_only_select ( "SELECT f(a).b FROM t WHERE f(a).b IS NOT NULL" ) ;
12563+ let expr = Expr :: CompositeAccess {
12564+ expr : Box :: new ( Expr :: Function ( Function {
12565+ name : ObjectName ( vec ! [ Ident :: new( "f" ) ] ) ,
12566+ uses_odbc_syntax : false ,
12567+ parameters : FunctionArguments :: None ,
12568+ args : FunctionArguments :: List ( FunctionArgumentList {
12569+ duplicate_treatment : None ,
12570+ args : vec ! [ FunctionArg :: Unnamed ( FunctionArgExpr :: Expr (
12571+ Expr :: Identifier ( Ident :: new( "a" ) ) ,
12572+ ) ) ] ,
12573+ clauses : vec ! [ ] ,
12574+ } ) ,
12575+ null_treatment : None ,
12576+ filter : None ,
12577+ over : None ,
12578+ within_group : vec ! [ ] ,
12579+ } ) ) ,
12580+ key : Ident :: new ( "b" ) ,
12581+ } ;
12582+
12583+ assert_eq ! ( stmt. projection[ 0 ] , SelectItem :: UnnamedExpr ( expr. clone( ) ) ) ;
12584+ assert_eq ! ( stmt. selection. unwrap( ) , Expr :: IsNotNull ( Box :: new( expr) ) ) ;
12585+
12586+ // Composite Access with quoted identifier
12587+ verified_only_select ( "SELECT f(a).\" an id\" " ) ;
12588+
12589+ // Composite Access in struct literal
12590+ all_dialects_where ( |d| d. supports_struct_literal ( ) ) . verified_stmt (
12591+ "SELECT * FROM t WHERE STRUCT(STRUCT(1 AS a, NULL AS b) AS c, NULL AS d).c.a IS NOT NULL" ,
12592+ ) ;
12593+ }
12594+
1250912595#[ test]
1251012596fn parse_create_table_with_enum_types ( ) {
1251112597 let sql = "CREATE TABLE t0 (foo ENUM8('a' = 1, 'b' = 2), bar ENUM16('a' = 1, 'b' = 2), baz ENUM('a', 'b'))" ;
0 commit comments