@@ -1471,6 +1471,173 @@ fn parse_json_ops_without_colon() {
14711471 }
14721472}
14731473
1474+ #[ test]
1475+ fn parse_json_object ( ) {
1476+ let dialects = TestedDialects :: new ( vec ! [
1477+ Box :: new( MsSqlDialect { } ) ,
1478+ Box :: new( PostgreSqlDialect { } ) ,
1479+ ] ) ;
1480+ let select = dialects. verified_only_select ( "SELECT JSON_OBJECT('name' : 'value', 'type' : 1)" ) ;
1481+ match expr_from_projection ( & select. projection [ 0 ] ) {
1482+ Expr :: Function ( Function {
1483+ args : FunctionArguments :: List ( FunctionArgumentList { args, .. } ) ,
1484+ ..
1485+ } ) => assert_eq ! (
1486+ & [
1487+ FunctionArg :: ExprNamed {
1488+ name: Expr :: Value ( Value :: SingleQuotedString ( "name" . into( ) ) ) ,
1489+ arg: FunctionArgExpr :: Expr ( Expr :: Value ( Value :: SingleQuotedString (
1490+ "value" . into( )
1491+ ) ) ) ,
1492+ operator: FunctionArgOperator :: Colon
1493+ } ,
1494+ FunctionArg :: ExprNamed {
1495+ name: Expr :: Value ( Value :: SingleQuotedString ( "type" . into( ) ) ) ,
1496+ arg: FunctionArgExpr :: Expr ( Expr :: Value ( number( "1" ) ) ) ,
1497+ operator: FunctionArgOperator :: Colon
1498+ }
1499+ ] ,
1500+ & args[ ..]
1501+ ) ,
1502+ _ => unreachable ! ( ) ,
1503+ }
1504+ let select = dialects
1505+ . verified_only_select ( "SELECT JSON_OBJECT('name' : 'value', 'type' : NULL ABSENT ON NULL)" ) ;
1506+ match expr_from_projection ( & select. projection [ 0 ] ) {
1507+ Expr :: Function ( Function {
1508+ args : FunctionArguments :: List ( FunctionArgumentList { args, clauses, .. } ) ,
1509+ ..
1510+ } ) => {
1511+ assert_eq ! (
1512+ & [
1513+ FunctionArg :: ExprNamed {
1514+ name: Expr :: Value ( Value :: SingleQuotedString ( "name" . into( ) ) ) ,
1515+ arg: FunctionArgExpr :: Expr ( Expr :: Value ( Value :: SingleQuotedString (
1516+ "value" . into( )
1517+ ) ) ) ,
1518+ operator: FunctionArgOperator :: Colon
1519+ } ,
1520+ FunctionArg :: ExprNamed {
1521+ name: Expr :: Value ( Value :: SingleQuotedString ( "type" . into( ) ) ) ,
1522+ arg: FunctionArgExpr :: Expr ( Expr :: Value ( Value :: Null ) ) ,
1523+ operator: FunctionArgOperator :: Colon
1524+ }
1525+ ] ,
1526+ & args[ ..]
1527+ ) ;
1528+ assert_eq ! (
1529+ & [ FunctionArgumentClause :: JsonNullClause (
1530+ JsonNullClause :: AbsentOnNull
1531+ ) ] ,
1532+ & clauses[ ..]
1533+ ) ;
1534+ }
1535+ _ => unreachable ! ( ) ,
1536+ }
1537+ let select = dialects. verified_only_select ( "SELECT JSON_OBJECT(NULL ON NULL)" ) ;
1538+ match expr_from_projection ( & select. projection [ 0 ] ) {
1539+ Expr :: Function ( Function {
1540+ args : FunctionArguments :: List ( FunctionArgumentList { args, clauses, .. } ) ,
1541+ ..
1542+ } ) => {
1543+ assert ! ( args. is_empty( ) ) ;
1544+ assert_eq ! (
1545+ & [ FunctionArgumentClause :: JsonNullClause (
1546+ JsonNullClause :: NullOnNull
1547+ ) ] ,
1548+ & clauses[ ..]
1549+ ) ;
1550+ }
1551+ _ => unreachable ! ( ) ,
1552+ }
1553+ let select = dialects. verified_only_select ( "SELECT JSON_OBJECT(ABSENT ON NULL)" ) ;
1554+ match expr_from_projection ( & select. projection [ 0 ] ) {
1555+ Expr :: Function ( Function {
1556+ args : FunctionArguments :: List ( FunctionArgumentList { args, clauses, .. } ) ,
1557+ ..
1558+ } ) => {
1559+ assert ! ( args. is_empty( ) ) ;
1560+ assert_eq ! (
1561+ & [ FunctionArgumentClause :: JsonNullClause (
1562+ JsonNullClause :: AbsentOnNull
1563+ ) ] ,
1564+ & clauses[ ..]
1565+ ) ;
1566+ }
1567+ _ => unreachable ! ( ) ,
1568+ }
1569+ let select = dialects. verified_only_select (
1570+ "SELECT JSON_OBJECT('name' : 'value', 'type' : JSON_ARRAY(1, 2) ABSENT ON NULL)" ,
1571+ ) ;
1572+ match expr_from_projection ( & select. projection [ 0 ] ) {
1573+ Expr :: Function ( Function {
1574+ args : FunctionArguments :: List ( FunctionArgumentList { args, clauses, .. } ) ,
1575+ ..
1576+ } ) => {
1577+ assert_eq ! (
1578+ & FunctionArg :: ExprNamed {
1579+ name: Expr :: Value ( Value :: SingleQuotedString ( "name" . into( ) ) ) ,
1580+ arg: FunctionArgExpr :: Expr ( Expr :: Value ( Value :: SingleQuotedString (
1581+ "value" . into( )
1582+ ) ) ) ,
1583+ operator: FunctionArgOperator :: Colon
1584+ } ,
1585+ & args[ 0 ]
1586+ ) ;
1587+ assert ! ( matches!(
1588+ args[ 1 ] ,
1589+ FunctionArg :: ExprNamed {
1590+ name: Expr :: Value ( Value :: SingleQuotedString ( _) ) ,
1591+ arg: FunctionArgExpr :: Expr ( Expr :: Function ( _) ) ,
1592+ operator: FunctionArgOperator :: Colon
1593+ }
1594+ ) ) ;
1595+ assert_eq ! (
1596+ & [ FunctionArgumentClause :: JsonNullClause (
1597+ JsonNullClause :: AbsentOnNull
1598+ ) ] ,
1599+ & clauses[ ..]
1600+ ) ;
1601+ }
1602+ _ => unreachable ! ( ) ,
1603+ }
1604+ let select = dialects. verified_only_select (
1605+ "SELECT JSON_OBJECT('name' : 'value', 'type' : JSON_OBJECT('type_id' : 1, 'name' : 'a') NULL ON NULL)" ,
1606+ ) ;
1607+ match expr_from_projection ( & select. projection [ 0 ] ) {
1608+ Expr :: Function ( Function {
1609+ args : FunctionArguments :: List ( FunctionArgumentList { args, clauses, .. } ) ,
1610+ ..
1611+ } ) => {
1612+ assert_eq ! (
1613+ & FunctionArg :: ExprNamed {
1614+ name: Expr :: Value ( Value :: SingleQuotedString ( "name" . into( ) ) ) ,
1615+ arg: FunctionArgExpr :: Expr ( Expr :: Value ( Value :: SingleQuotedString (
1616+ "value" . into( )
1617+ ) ) ) ,
1618+ operator: FunctionArgOperator :: Colon
1619+ } ,
1620+ & args[ 0 ]
1621+ ) ;
1622+ assert ! ( matches!(
1623+ args[ 1 ] ,
1624+ FunctionArg :: ExprNamed {
1625+ name: Expr :: Value ( Value :: SingleQuotedString ( _) ) ,
1626+ arg: FunctionArgExpr :: Expr ( Expr :: Function ( _) ) ,
1627+ operator: FunctionArgOperator :: Colon
1628+ }
1629+ ) ) ;
1630+ assert_eq ! (
1631+ & [ FunctionArgumentClause :: JsonNullClause (
1632+ JsonNullClause :: NullOnNull
1633+ ) ] ,
1634+ & clauses[ ..]
1635+ ) ;
1636+ }
1637+ _ => unreachable ! ( ) ,
1638+ }
1639+ }
1640+
14741641#[ test]
14751642fn parse_mod_no_spaces ( ) {
14761643 use self :: Expr :: * ;
@@ -4416,7 +4583,10 @@ fn parse_explain_query_plan() {
44164583
44174584#[ test]
44184585fn parse_named_argument_function ( ) {
4419- let dialects = all_dialects_where ( |d| d. supports_named_fn_args_with_rarrow_operator ( ) ) ;
4586+ let dialects = all_dialects_where ( |d| {
4587+ d. supports_named_fn_args_with_rarrow_operator ( )
4588+ && !d. supports_named_fn_args_with_expr_name ( )
4589+ } ) ;
44204590 let sql = "SELECT FUN(a => '1', b => '2') FROM foo" ;
44214591 let select = dialects. verified_only_select ( sql) ;
44224592
0 commit comments