mirror of
https://github.com/apache/datafusion-sqlparser-rs.git
synced 2025-08-04 06:18:17 +00:00
support json_object('k':'v')
in postgres (#1546)
This commit is contained in:
parent
fd21fae297
commit
525d1780e8
3 changed files with 191 additions and 160 deletions
|
@ -793,165 +793,6 @@ fn parse_for_json_expect_ast() {
|
|||
|
||||
#[test]
|
||||
fn parse_mssql_json_object() {
|
||||
let select = ms().verified_only_select("SELECT JSON_OBJECT('name' : 'value', 'type' : 1)");
|
||||
match expr_from_projection(&select.projection[0]) {
|
||||
Expr::Function(Function {
|
||||
args: FunctionArguments::List(FunctionArgumentList { args, .. }),
|
||||
..
|
||||
}) => assert_eq!(
|
||||
&[
|
||||
FunctionArg::ExprNamed {
|
||||
name: Expr::Value(Value::SingleQuotedString("name".into())),
|
||||
arg: FunctionArgExpr::Expr(Expr::Value(Value::SingleQuotedString(
|
||||
"value".into()
|
||||
))),
|
||||
operator: FunctionArgOperator::Colon
|
||||
},
|
||||
FunctionArg::ExprNamed {
|
||||
name: Expr::Value(Value::SingleQuotedString("type".into())),
|
||||
arg: FunctionArgExpr::Expr(Expr::Value(number("1"))),
|
||||
operator: FunctionArgOperator::Colon
|
||||
}
|
||||
],
|
||||
&args[..]
|
||||
),
|
||||
_ => unreachable!(),
|
||||
}
|
||||
let select = ms()
|
||||
.verified_only_select("SELECT JSON_OBJECT('name' : 'value', 'type' : NULL ABSENT ON NULL)");
|
||||
match expr_from_projection(&select.projection[0]) {
|
||||
Expr::Function(Function {
|
||||
args: FunctionArguments::List(FunctionArgumentList { args, clauses, .. }),
|
||||
..
|
||||
}) => {
|
||||
assert_eq!(
|
||||
&[
|
||||
FunctionArg::ExprNamed {
|
||||
name: Expr::Value(Value::SingleQuotedString("name".into())),
|
||||
arg: FunctionArgExpr::Expr(Expr::Value(Value::SingleQuotedString(
|
||||
"value".into()
|
||||
))),
|
||||
operator: FunctionArgOperator::Colon
|
||||
},
|
||||
FunctionArg::ExprNamed {
|
||||
name: Expr::Value(Value::SingleQuotedString("type".into())),
|
||||
arg: FunctionArgExpr::Expr(Expr::Value(Value::Null)),
|
||||
operator: FunctionArgOperator::Colon
|
||||
}
|
||||
],
|
||||
&args[..]
|
||||
);
|
||||
assert_eq!(
|
||||
&[FunctionArgumentClause::JsonNullClause(
|
||||
JsonNullClause::AbsentOnNull
|
||||
)],
|
||||
&clauses[..]
|
||||
);
|
||||
}
|
||||
_ => unreachable!(),
|
||||
}
|
||||
let select = ms().verified_only_select("SELECT JSON_OBJECT(NULL ON NULL)");
|
||||
match expr_from_projection(&select.projection[0]) {
|
||||
Expr::Function(Function {
|
||||
args: FunctionArguments::List(FunctionArgumentList { args, clauses, .. }),
|
||||
..
|
||||
}) => {
|
||||
assert!(args.is_empty());
|
||||
assert_eq!(
|
||||
&[FunctionArgumentClause::JsonNullClause(
|
||||
JsonNullClause::NullOnNull
|
||||
)],
|
||||
&clauses[..]
|
||||
);
|
||||
}
|
||||
_ => unreachable!(),
|
||||
}
|
||||
let select = ms().verified_only_select("SELECT JSON_OBJECT(ABSENT ON NULL)");
|
||||
match expr_from_projection(&select.projection[0]) {
|
||||
Expr::Function(Function {
|
||||
args: FunctionArguments::List(FunctionArgumentList { args, clauses, .. }),
|
||||
..
|
||||
}) => {
|
||||
assert!(args.is_empty());
|
||||
assert_eq!(
|
||||
&[FunctionArgumentClause::JsonNullClause(
|
||||
JsonNullClause::AbsentOnNull
|
||||
)],
|
||||
&clauses[..]
|
||||
);
|
||||
}
|
||||
_ => unreachable!(),
|
||||
}
|
||||
let select = ms().verified_only_select(
|
||||
"SELECT JSON_OBJECT('name' : 'value', 'type' : JSON_ARRAY(1, 2) ABSENT ON NULL)",
|
||||
);
|
||||
match expr_from_projection(&select.projection[0]) {
|
||||
Expr::Function(Function {
|
||||
args: FunctionArguments::List(FunctionArgumentList { args, clauses, .. }),
|
||||
..
|
||||
}) => {
|
||||
assert_eq!(
|
||||
&FunctionArg::ExprNamed {
|
||||
name: Expr::Value(Value::SingleQuotedString("name".into())),
|
||||
arg: FunctionArgExpr::Expr(Expr::Value(Value::SingleQuotedString(
|
||||
"value".into()
|
||||
))),
|
||||
operator: FunctionArgOperator::Colon
|
||||
},
|
||||
&args[0]
|
||||
);
|
||||
assert!(matches!(
|
||||
args[1],
|
||||
FunctionArg::ExprNamed {
|
||||
name: Expr::Value(Value::SingleQuotedString(_)),
|
||||
arg: FunctionArgExpr::Expr(Expr::Function(_)),
|
||||
operator: FunctionArgOperator::Colon
|
||||
}
|
||||
));
|
||||
assert_eq!(
|
||||
&[FunctionArgumentClause::JsonNullClause(
|
||||
JsonNullClause::AbsentOnNull
|
||||
)],
|
||||
&clauses[..]
|
||||
);
|
||||
}
|
||||
_ => unreachable!(),
|
||||
}
|
||||
let select = ms().verified_only_select(
|
||||
"SELECT JSON_OBJECT('name' : 'value', 'type' : JSON_OBJECT('type_id' : 1, 'name' : 'a') NULL ON NULL)",
|
||||
);
|
||||
match expr_from_projection(&select.projection[0]) {
|
||||
Expr::Function(Function {
|
||||
args: FunctionArguments::List(FunctionArgumentList { args, clauses, .. }),
|
||||
..
|
||||
}) => {
|
||||
assert_eq!(
|
||||
&FunctionArg::ExprNamed {
|
||||
name: Expr::Value(Value::SingleQuotedString("name".into())),
|
||||
arg: FunctionArgExpr::Expr(Expr::Value(Value::SingleQuotedString(
|
||||
"value".into()
|
||||
))),
|
||||
operator: FunctionArgOperator::Colon
|
||||
},
|
||||
&args[0]
|
||||
);
|
||||
assert!(matches!(
|
||||
args[1],
|
||||
FunctionArg::ExprNamed {
|
||||
name: Expr::Value(Value::SingleQuotedString(_)),
|
||||
arg: FunctionArgExpr::Expr(Expr::Function(_)),
|
||||
operator: FunctionArgOperator::Colon
|
||||
}
|
||||
));
|
||||
assert_eq!(
|
||||
&[FunctionArgumentClause::JsonNullClause(
|
||||
JsonNullClause::NullOnNull
|
||||
)],
|
||||
&clauses[..]
|
||||
);
|
||||
}
|
||||
_ => unreachable!(),
|
||||
}
|
||||
let select = ms().verified_only_select(
|
||||
"SELECT JSON_OBJECT('user_name' : USER_NAME(), LOWER(@id_key) : @id_value, 'sid' : (SELECT @@SPID) ABSENT ON NULL)",
|
||||
);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue