Add FunctionArgExpr and remove Expr::[Qualified]Wildcard, (#378)

* Add FunctionArgExpr and remove Expr::[Qualified]Wildcard,

There is no use case of `Expr::Wildcard` and `Expr::QualifiedWildcard` only except for function argments.
Add `FunctionArgExpr` to have `Wildcard` and `QualifiedWildcard`, and remove wildcards in `Expr`.

* Apply `FunctionArgExpr` to sqlparser_mysql tests
This commit is contained in:
Taehoon Moon 2021-12-15 20:35:37 +09:00 committed by GitHub
parent 4c121a92a6
commit 823635d2fc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 120 additions and 61 deletions

View file

@ -363,10 +363,19 @@ fn parse_select_wildcard() {
])),
only(&select.projection)
);
let sql = "SELECT * + * FROM foo;";
let result = parse_sql_statements(sql);
assert_eq!(
ParserError::ParserError("Expected end of statement, found: +".to_string()),
result.unwrap_err(),
);
}
#[test]
fn parse_count_wildcard() {
verified_only_select("SELECT COUNT(*) FROM Order WHERE id = 10");
verified_only_select(
"SELECT COUNT(Employee.*) FROM Order JOIN Employee ON Order.employee = Employee.id",
);
@ -425,7 +434,7 @@ fn parse_select_count_wildcard() {
assert_eq!(
&Expr::Function(Function {
name: ObjectName(vec![Ident::new("COUNT")]),
args: vec![FunctionArg::Unnamed(Expr::Wildcard)],
args: vec![FunctionArg::Unnamed(FunctionArgExpr::Wildcard)],
over: None,
distinct: false,
}),
@ -440,10 +449,10 @@ fn parse_select_count_distinct() {
assert_eq!(
&Expr::Function(Function {
name: ObjectName(vec![Ident::new("COUNT")]),
args: vec![FunctionArg::Unnamed(Expr::UnaryOp {
args: vec![FunctionArg::Unnamed(FunctionArgExpr::Expr(Expr::UnaryOp {
op: UnaryOperator::Plus,
expr: Box::new(Expr::Identifier(Ident::new("x"))),
})],
}))],
over: None,
distinct: true,
}),
@ -1156,7 +1165,7 @@ fn parse_select_having() {
Some(Expr::BinaryOp {
left: Box::new(Expr::Function(Function {
name: ObjectName(vec![Ident::new("COUNT")]),
args: vec![FunctionArg::Unnamed(Expr::Wildcard)],
args: vec![FunctionArg::Unnamed(FunctionArgExpr::Wildcard)],
over: None,
distinct: false,
})),
@ -1965,7 +1974,9 @@ fn parse_scalar_function_in_projection() {
assert_eq!(
&Expr::Function(Function {
name: ObjectName(vec![Ident::new("sqrt")]),
args: vec![FunctionArg::Unnamed(Expr::Identifier(Ident::new("id")))],
args: vec![FunctionArg::Unnamed(FunctionArgExpr::Expr(
Expr::Identifier(Ident::new("id"))
))],
over: None,
distinct: false,
}),
@ -2032,11 +2043,15 @@ fn parse_named_argument_function() {
args: vec![
FunctionArg::Named {
name: Ident::new("a"),
arg: Expr::Value(Value::SingleQuotedString("1".to_owned()))
arg: FunctionArgExpr::Expr(Expr::Value(Value::SingleQuotedString(
"1".to_owned()
))),
},
FunctionArg::Named {
name: Ident::new("b"),
arg: Expr::Value(Value::SingleQuotedString("2".to_owned()))
arg: FunctionArgExpr::Expr(Expr::Value(Value::SingleQuotedString(
"2".to_owned()
))),
},
],
over: None,
@ -2296,9 +2311,9 @@ fn parse_table_function() {
TableFactor::TableFunction { expr, alias } => {
let expected_expr = Expr::Function(Function {
name: ObjectName(vec![Ident::new("FUN")]),
args: vec![FunctionArg::Unnamed(Expr::Value(
args: vec![FunctionArg::Unnamed(FunctionArgExpr::Expr(Expr::Value(
Value::SingleQuotedString("1".to_owned()),
))],
)))],
over: None,
distinct: false,
});