Merge pull request #89 from benesch/sqlfunction-struct

Extract a SQLFunction struct
This commit is contained in:
Nikhil Benesch 2019-06-03 11:09:27 -04:00 committed by GitHub
commit a3aaa49a7e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 40 additions and 36 deletions

View file

@ -232,12 +232,12 @@ fn parse_select_count_wildcard() {
let sql = "SELECT COUNT(*) FROM customer";
let select = verified_only_select(sql);
assert_eq!(
&ASTNode::SQLFunction {
&ASTNode::SQLFunction(SQLFunction {
name: SQLObjectName(vec!["COUNT".to_string()]),
args: vec![ASTNode::SQLWildcard],
over: None,
distinct: false,
},
}),
expr_from_projection(only(&select.projection))
);
}
@ -247,7 +247,7 @@ fn parse_select_count_distinct() {
let sql = "SELECT COUNT(DISTINCT + x) FROM customer";
let select = verified_only_select(sql);
assert_eq!(
&ASTNode::SQLFunction {
&ASTNode::SQLFunction(SQLFunction {
name: SQLObjectName(vec!["COUNT".to_string()]),
args: vec![ASTNode::SQLUnary {
operator: SQLOperator::Plus,
@ -255,7 +255,7 @@ fn parse_select_count_distinct() {
}],
over: None,
distinct: true,
},
}),
expr_from_projection(only(&select.projection))
);
@ -886,12 +886,12 @@ fn parse_scalar_function_in_projection() {
let sql = "SELECT sqrt(id) FROM foo";
let select = verified_only_select(sql);
assert_eq!(
&ASTNode::SQLFunction {
&ASTNode::SQLFunction(SQLFunction {
name: SQLObjectName(vec!["sqrt".to_string()]),
args: vec![ASTNode::SQLIdentifier("id".to_string())],
over: None,
distinct: false,
},
}),
expr_from_projection(only(&select.projection))
);
}
@ -909,7 +909,7 @@ fn parse_window_functions() {
let select = verified_only_select(sql);
assert_eq!(4, select.projection.len());
assert_eq!(
&ASTNode::SQLFunction {
&ASTNode::SQLFunction(SQLFunction {
name: SQLObjectName(vec!["row_number".to_string()]),
args: vec![],
over: Some(SQLWindowSpec {
@ -921,7 +921,7 @@ fn parse_window_functions() {
window_frame: None,
}),
distinct: false,
},
}),
expr_from_projection(&select.projection[0])
);
}
@ -988,12 +988,12 @@ fn parse_delimited_identifiers() {
expr_from_projection(&select.projection[0]),
);
assert_eq!(
&ASTNode::SQLFunction {
&ASTNode::SQLFunction(SQLFunction {
name: SQLObjectName(vec![r#""myfun""#.to_string()]),
args: vec![],
over: None,
distinct: false,
},
}),
expr_from_projection(&select.projection[1]),
);
match &select.projection[2] {