Uploaded image for project: 'Apache Arrow'
  1. Apache Arrow
  2. ARROW-9520

[Rust] [DataFusion] Can't alias an aggregate expression

    XMLWordPrintableJSON

Details

    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

          Activity

            People

              Unassigned Unassigned
              jorgecarleitao Jorge Leitão
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Time Tracking

                  Estimated:
                  Original Estimate - Not Specified
                  Not Specified
                  Remaining:
                  Remaining Estimate - 0h
                  0h
                  Logged:
                  Time Spent - 1h 10m
                  1h 10m