mirror of
https://github.com/apache/datafusion-sqlparser-rs.git
synced 2025-08-30 10:47:22 +00:00
Add support for first, last aggregate function parsing (#882)
* Add order by parsing to functions * Fix doc error * minor changes
This commit is contained in:
parent
33b12acce7
commit
1b86abebe2
12 changed files with 96 additions and 7 deletions
|
@ -840,6 +840,7 @@ fn parse_select_count_wildcard() {
|
|||
over: None,
|
||||
distinct: false,
|
||||
special: false,
|
||||
order_by: vec![],
|
||||
}),
|
||||
expr_from_projection(only(&select.projection))
|
||||
);
|
||||
|
@ -859,6 +860,7 @@ fn parse_select_count_distinct() {
|
|||
over: None,
|
||||
distinct: true,
|
||||
special: false,
|
||||
order_by: vec![],
|
||||
}),
|
||||
expr_from_projection(only(&select.projection))
|
||||
);
|
||||
|
@ -1696,6 +1698,7 @@ fn parse_select_having() {
|
|||
over: None,
|
||||
distinct: false,
|
||||
special: false,
|
||||
order_by: vec![],
|
||||
})),
|
||||
op: BinaryOperator::Gt,
|
||||
right: Box::new(Expr::Value(number("1"))),
|
||||
|
@ -1729,6 +1732,7 @@ fn parse_select_qualify() {
|
|||
}),
|
||||
distinct: false,
|
||||
special: false,
|
||||
order_by: vec![],
|
||||
})),
|
||||
op: BinaryOperator::Eq,
|
||||
right: Box::new(Expr::Value(number("1"))),
|
||||
|
@ -2076,6 +2080,29 @@ fn parse_array_agg_func() {
|
|||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn parse_agg_with_order_by() {
|
||||
let supported_dialects = TestedDialects {
|
||||
dialects: vec![
|
||||
Box::new(GenericDialect {}),
|
||||
Box::new(PostgreSqlDialect {}),
|
||||
Box::new(MsSqlDialect {}),
|
||||
Box::new(AnsiDialect {}),
|
||||
Box::new(HiveDialect {}),
|
||||
],
|
||||
options: None,
|
||||
};
|
||||
|
||||
for sql in [
|
||||
"SELECT FIRST_VALUE(x ORDER BY x) AS a FROM T",
|
||||
"SELECT FIRST_VALUE(x ORDER BY x) FROM tbl",
|
||||
"SELECT LAST_VALUE(x ORDER BY x, y) AS a FROM T",
|
||||
"SELECT LAST_VALUE(x ORDER BY x ASC, y DESC) AS a FROM T",
|
||||
] {
|
||||
supported_dialects.verified_stmt(sql);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn parse_create_table() {
|
||||
let sql = "CREATE TABLE uk_cities (\
|
||||
|
@ -3121,6 +3148,7 @@ fn parse_scalar_function_in_projection() {
|
|||
over: None,
|
||||
distinct: false,
|
||||
special: false,
|
||||
order_by: vec![],
|
||||
}),
|
||||
expr_from_projection(only(&select.projection))
|
||||
);
|
||||
|
@ -3239,6 +3267,7 @@ fn parse_named_argument_function() {
|
|||
over: None,
|
||||
distinct: false,
|
||||
special: false,
|
||||
order_by: vec![],
|
||||
}),
|
||||
expr_from_projection(only(&select.projection))
|
||||
);
|
||||
|
@ -3277,6 +3306,7 @@ fn parse_window_functions() {
|
|||
}),
|
||||
distinct: false,
|
||||
special: false,
|
||||
order_by: vec![],
|
||||
}),
|
||||
expr_from_projection(&select.projection[0])
|
||||
);
|
||||
|
@ -3675,6 +3705,7 @@ fn parse_at_timezone() {
|
|||
over: None,
|
||||
distinct: false,
|
||||
special: false,
|
||||
order_by: vec![],
|
||||
})),
|
||||
time_zone: "UTC-06:00".to_string(),
|
||||
},
|
||||
|
@ -3701,6 +3732,7 @@ fn parse_at_timezone() {
|
|||
over: None,
|
||||
distinct: false,
|
||||
special: false,
|
||||
order_by: vec![],
|
||||
},)),
|
||||
time_zone: "UTC-06:00".to_string(),
|
||||
},),),
|
||||
|
@ -3711,6 +3743,7 @@ fn parse_at_timezone() {
|
|||
over: None,
|
||||
distinct: false,
|
||||
special: false,
|
||||
order_by: vec![],
|
||||
},),
|
||||
alias: Ident {
|
||||
value: "hour".to_string(),
|
||||
|
@ -3868,6 +3901,7 @@ fn parse_table_function() {
|
|||
over: None,
|
||||
distinct: false,
|
||||
special: false,
|
||||
order_by: vec![],
|
||||
});
|
||||
assert_eq!(expr, expected_expr);
|
||||
assert_eq!(alias, table_alias("a"))
|
||||
|
@ -6292,6 +6326,7 @@ fn parse_time_functions() {
|
|||
over: None,
|
||||
distinct: false,
|
||||
special: false,
|
||||
order_by: vec![],
|
||||
}),
|
||||
expr_from_projection(&select.projection[0])
|
||||
);
|
||||
|
@ -6308,6 +6343,7 @@ fn parse_time_functions() {
|
|||
over: None,
|
||||
distinct: false,
|
||||
special: false,
|
||||
order_by: vec![],
|
||||
}),
|
||||
expr_from_projection(&select.projection[0])
|
||||
);
|
||||
|
@ -6324,6 +6360,7 @@ fn parse_time_functions() {
|
|||
over: None,
|
||||
distinct: false,
|
||||
special: false,
|
||||
order_by: vec![],
|
||||
}),
|
||||
expr_from_projection(&select.projection[0])
|
||||
);
|
||||
|
@ -6340,6 +6377,7 @@ fn parse_time_functions() {
|
|||
over: None,
|
||||
distinct: false,
|
||||
special: false,
|
||||
order_by: vec![],
|
||||
}),
|
||||
expr_from_projection(&select.projection[0])
|
||||
);
|
||||
|
@ -6356,6 +6394,7 @@ fn parse_time_functions() {
|
|||
over: None,
|
||||
distinct: false,
|
||||
special: false,
|
||||
order_by: vec![],
|
||||
}),
|
||||
expr_from_projection(&select.projection[0])
|
||||
);
|
||||
|
@ -6820,6 +6859,7 @@ fn parse_pivot_table() {
|
|||
over: None,
|
||||
distinct: false,
|
||||
special: false,
|
||||
order_by: vec![],
|
||||
}),
|
||||
value_column: vec![Ident::new("a"), Ident::new("MONTH")],
|
||||
pivot_values: vec![
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue