Parse an aggregate function in a select list
(agg_fn: Function, alias: SqlIdent)
| 153 | |
| 154 | /// Parse an aggregate function in a select list |
| 155 | fn parse_agg_fn(agg_fn: Function, alias: SqlIdent) -> SqlParseResult<Project> { |
| 156 | fn is_count(name: &ObjectName) -> bool { |
| 157 | name.0.len() == 1 |
| 158 | && name |
| 159 | .0 |
| 160 | .first() |
| 161 | .is_some_and(|Ident { value, .. }| value.to_lowercase() == "count") |
| 162 | } |
| 163 | match agg_fn { |
| 164 | Function { |
| 165 | name, |
| 166 | args, |
| 167 | over: None, |
| 168 | distinct: false, |
| 169 | special: false, |
| 170 | order_by, |
| 171 | } if is_count(&name) |
| 172 | && order_by.is_empty() |
| 173 | && args.len() == 1 |
| 174 | && args |
| 175 | .first() |
| 176 | .is_some_and(|arg| matches!(arg, FunctionArg::Unnamed(FunctionArgExpr::Wildcard))) => |
| 177 | { |
| 178 | Ok(Project::Count(alias)) |
| 179 | } |
| 180 | agg_fn => Err(SqlUnsupported::Aggregate(agg_fn).into()), |
| 181 | } |
| 182 | } |
| 183 | |
| 184 | /// Parse an item in a SELECT clause |
| 185 | pub(crate) fn parse_project_elem(item: SelectItem) -> SqlParseResult<ProjectElem> { |