mirror of
https://github.com/apache/datafusion-sqlparser-rs.git
synced 2025-08-30 18:57:21 +00:00
Support COUNT(DISTINCT x) and similar
This commit is contained in:
parent
4f944dd4aa
commit
72ced4bffe
3 changed files with 65 additions and 4 deletions
|
@ -197,11 +197,44 @@ fn parse_select_count_wildcard() {
|
|||
name: SQLObjectName(vec!["COUNT".to_string()]),
|
||||
args: vec![ASTNode::SQLWildcard],
|
||||
over: None,
|
||||
distinct: false,
|
||||
},
|
||||
expr_from_projection(only(&select.projection))
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn parse_select_count_distinct() {
|
||||
let sql = "SELECT COUNT(DISTINCT + x) FROM customer";
|
||||
let select = verified_only_select(sql);
|
||||
assert_eq!(
|
||||
&ASTNode::SQLFunction {
|
||||
name: SQLObjectName(vec!["COUNT".to_string()]),
|
||||
args: vec![ASTNode::SQLUnary {
|
||||
operator: SQLOperator::Plus,
|
||||
expr: Box::new(ASTNode::SQLIdentifier("x".to_string()))
|
||||
}],
|
||||
over: None,
|
||||
distinct: true,
|
||||
},
|
||||
expr_from_projection(only(&select.projection))
|
||||
);
|
||||
|
||||
one_statement_parses_to(
|
||||
"SELECT COUNT(ALL + x) FROM customer",
|
||||
"SELECT COUNT(+ x) FROM customer",
|
||||
);
|
||||
|
||||
let sql = "SELECT COUNT(ALL DISTINCT + x) FROM customer";
|
||||
let res = parse_sql_statements(sql);
|
||||
assert_eq!(
|
||||
ParserError::ParserError(
|
||||
"Cannot specify both ALL and DISTINCT in function: COUNT".to_string()
|
||||
),
|
||||
res.unwrap_err()
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn parse_not() {
|
||||
let sql = "SELECT id FROM customer WHERE NOT salary = ''";
|
||||
|
@ -662,6 +695,7 @@ fn parse_scalar_function_in_projection() {
|
|||
name: SQLObjectName(vec!["sqrt".to_string()]),
|
||||
args: vec![ASTNode::SQLIdentifier("id".to_string())],
|
||||
over: None,
|
||||
distinct: false,
|
||||
},
|
||||
expr_from_projection(only(&select.projection))
|
||||
);
|
||||
|
@ -690,7 +724,8 @@ fn parse_window_functions() {
|
|||
asc: Some(false)
|
||||
}],
|
||||
window_frame: None,
|
||||
})
|
||||
}),
|
||||
distinct: false,
|
||||
},
|
||||
expr_from_projection(&select.projection[0])
|
||||
);
|
||||
|
@ -762,6 +797,7 @@ fn parse_delimited_identifiers() {
|
|||
name: SQLObjectName(vec![r#""myfun""#.to_string()]),
|
||||
args: vec![],
|
||||
over: None,
|
||||
distinct: false,
|
||||
},
|
||||
expr_from_projection(&select.projection[1]),
|
||||
);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue