Skip to content

single_distinct_to_groupby panic when group by expr is a binaryExpr #2994

@jiacai2050

Description

@jiacai2050

Describe the bug

single_distinct_to_groupby panic when group by expr is a binaryExpr, with error message like this:

thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: SchemaError(FieldNotFound { qualifier: Some("users"), name: "id", valid_fields: Some(["users.id + Int64(1)", "alias1"]) })', datafusion/optimizer/src/single_distinct_to_groupby.rs:117:72

To Reproduce
Based on https://github.com/apache/arrow-datafusion/blob/e47c4eb1ac8a5c3c07a0ed2bad74ecd6509bae7b/datafusion-examples/examples/memtable.rs#L39,

Change sql to following will reproduce this error.

SELECT id+1 as id, count(distinct(bank_account)) 
FROM users
group by id+1
order by id

Expected behavior
No error

Additional context
Add any other context about the problem here.

Metadata

Metadata

Assignees

No one assigned

    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