Details
-
Bug
-
Status: Resolved
-
Major
-
Resolution: Fixed
-
None
Description
The following test (on execute) fails:
#[test] fn aggregate_with_alias() -> Result<()> { let results = execute("SELECT c1, COUNT(c2) AS count FROM test GROUP BY c1", 4)?; assert_eq!(field_names(batch), vec!["c1", "count"]); let expected = vec!["0,10", "1,10", "2,10", "3,10"]; let mut rows = test::format_batch(&batch); rows.sort(); assert_eq!(rows, expected); Ok(()) }
The root cause is that, in sql::planner, we interpret COUNT(c2) AS count as An Expr::Alias, which fails the is_aggregate_expr condition, thus being interpreted as grouped expression instead of an aggregated expression. This raises the Error
General("Projection references non-aggregate values")
The planner could interpret the statement above as two steps: an aggregation followed by a projection. Alternatively, we can allow aliases to be valid aggregation expressions.
Attachments
Issue Links
- duplicates
-
ARROW-9677 [Rust] [DataFusion] Aggregate queries that don't include group column in select list error with "Projection references non-aggregate values"
- Closed
- links to