Skip to content

Group by incorrectly works with alias.  #2430

@comphead

Description

@comphead

Describe the bug
Group by incorrectly works with alias. The query fails with "Projection references non-aggregate values"
`

To Reproduce

async fn csv_query_group_by_substr() -> Result<()> {
    let ctx = SessionContext::new();
    register_aggregate_csv(&ctx).await?;
    let sql = "SELECT substr(c1, 1, 1) c1 \
        FROM aggregate_test_100 \
        GROUP BY substr(c1, 1, 1) \
        ";
    let actual = execute_to_batches(&ctx, sql).await;
    let expected = vec![
        "+----+-----------------------------+",
        "| c1 | AVG(aggregate_test_100.c12) |",
        "+----+-----------------------------+",
        "| a  | 0.48754517466109415         |",
        "| b  | 0.41040709263815384         |",
        "| c  | 0.6600456536439784          |",
        "| d  | 0.48855379387549824         |",
        "| e  | 0.48600669271341534         |",
        "+----+-----------------------------+",
    ];
    assert_batches_sorted_eq!(expected, &actual);
    Ok(())
}

Expected behavior
Test should pass

Additional context
None

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions