Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/dialect/generic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,4 +163,8 @@ impl Dialect for GenericDialect {
fn supports_comma_separated_set_assignments(&self) -> bool {
true
}

fn supports_filter_during_aggregation(&self) -> bool {
true
}
}
18 changes: 15 additions & 3 deletions tests/sqlparser_common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11642,16 +11642,28 @@ fn parse_connect_by() {

#[test]
fn test_selective_aggregation() {
let testing_dialects = all_dialects_where(|d| d.supports_filter_during_aggregation());
let expected_dialects: Vec<Box<dyn Dialect>> = vec![
Box::new(PostgreSqlDialect {}),
Box::new(DatabricksDialect {}),
Box::new(HiveDialect {}),
Box::new(SQLiteDialect {}),
Box::new(DuckDbDialect {}),
Box::new(GenericDialect {}),
];
assert_eq!(testing_dialects.dialects.len(), expected_dialects.len());
expected_dialects
.into_iter()
.for_each(|d| assert!(d.supports_filter_during_aggregation()));
Comment on lines +11645 to +11657
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I list all the dialects expected to support filtering during aggregation.


let sql = concat!(
"SELECT ",
"ARRAY_AGG(name) FILTER (WHERE name IS NOT NULL), ",
"ARRAY_AGG(name) FILTER (WHERE name LIKE 'a%') AS agg2 ",
"FROM region"
);
assert_eq!(
all_dialects_where(|d| d.supports_filter_during_aggregation())
.verified_only_select(sql)
.projection,
testing_dialects.verified_only_select(sql).projection,
vec![
SelectItem::UnnamedExpr(Expr::Function(Function {
name: ObjectName::from(vec![Ident::new("ARRAY_AGG")]),
Expand Down