mirror of
https://github.com/apache/datafusion-sqlparser-rs.git
synced 2025-08-31 19:27:21 +00:00
Parse ARRAY_AGG for Bigquery and Snowflake (#662)
This commit is contained in:
parent
0428ac742b
commit
87b4a168cb
8 changed files with 156 additions and 4 deletions
|
@ -224,6 +224,17 @@ fn parse_similar_to() {
|
|||
chk(true);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn parse_array_agg_func() {
|
||||
for sql in [
|
||||
"SELECT ARRAY_AGG(x ORDER BY x) AS a FROM T",
|
||||
"SELECT ARRAY_AGG(x ORDER BY x LIMIT 2) FROM tbl",
|
||||
"SELECT ARRAY_AGG(DISTINCT x ORDER BY x LIMIT 2) FROM tbl",
|
||||
] {
|
||||
bigquery().verified_stmt(sql);
|
||||
}
|
||||
}
|
||||
|
||||
fn bigquery() -> TestedDialects {
|
||||
TestedDialects {
|
||||
dialects: vec![Box::new(BigQueryDialect {})],
|
||||
|
|
|
@ -1777,6 +1777,27 @@ fn parse_listagg() {
|
|||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn parse_array_agg_func() {
|
||||
let supported_dialects = TestedDialects {
|
||||
dialects: vec![
|
||||
Box::new(GenericDialect {}),
|
||||
Box::new(PostgreSqlDialect {}),
|
||||
Box::new(MsSqlDialect {}),
|
||||
Box::new(AnsiDialect {}),
|
||||
Box::new(HiveDialect {}),
|
||||
],
|
||||
};
|
||||
|
||||
for sql in [
|
||||
"SELECT ARRAY_AGG(x ORDER BY x) AS a FROM T",
|
||||
"SELECT ARRAY_AGG(x ORDER BY x LIMIT 2) FROM tbl",
|
||||
"SELECT ARRAY_AGG(DISTINCT x ORDER BY x LIMIT 2) FROM tbl",
|
||||
] {
|
||||
supported_dialects.verified_stmt(sql);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn parse_create_table() {
|
||||
let sql = "CREATE TABLE uk_cities (\
|
||||
|
|
|
@ -281,8 +281,8 @@ fn parse_create_function() {
|
|||
#[test]
|
||||
fn filtering_during_aggregation() {
|
||||
let rename = "SELECT \
|
||||
array_agg(name) FILTER (WHERE name IS NOT NULL), \
|
||||
array_agg(name) FILTER (WHERE name LIKE 'a%') \
|
||||
ARRAY_AGG(name) FILTER (WHERE name IS NOT NULL), \
|
||||
ARRAY_AGG(name) FILTER (WHERE name LIKE 'a%') \
|
||||
FROM region";
|
||||
println!("{}", hive().verified_stmt(rename));
|
||||
}
|
||||
|
@ -290,8 +290,8 @@ fn filtering_during_aggregation() {
|
|||
#[test]
|
||||
fn filtering_during_aggregation_aliased() {
|
||||
let rename = "SELECT \
|
||||
array_agg(name) FILTER (WHERE name IS NOT NULL) AS agg1, \
|
||||
array_agg(name) FILTER (WHERE name LIKE 'a%') AS agg2 \
|
||||
ARRAY_AGG(name) FILTER (WHERE name IS NOT NULL) AS agg1, \
|
||||
ARRAY_AGG(name) FILTER (WHERE name LIKE 'a%') AS agg2 \
|
||||
FROM region";
|
||||
println!("{}", hive().verified_stmt(rename));
|
||||
}
|
||||
|
|
|
@ -334,6 +334,25 @@ fn parse_similar_to() {
|
|||
chk(true);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_array_agg_func() {
|
||||
for sql in [
|
||||
"SELECT ARRAY_AGG(x) WITHIN GROUP (ORDER BY x) AS a FROM T",
|
||||
"SELECT ARRAY_AGG(DISTINCT x) WITHIN GROUP (ORDER BY x ASC) FROM tbl",
|
||||
] {
|
||||
snowflake().verified_stmt(sql);
|
||||
}
|
||||
|
||||
let sql = "select array_agg(x order by x) as a from T";
|
||||
let result = snowflake().parse_sql_statements(sql);
|
||||
assert_eq!(
|
||||
result,
|
||||
Err(ParserError::ParserError(String::from(
|
||||
"Expected ), found: order"
|
||||
)))
|
||||
)
|
||||
}
|
||||
|
||||
fn snowflake() -> TestedDialects {
|
||||
TestedDialects {
|
||||
dialects: vec![Box::new(SnowflakeDialect {})],
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue