Skip to content

Regression: Count distinct with date_part/date_bin does not work #8175

@NGA-TRAN

Description

@NGA-TRAN

Describe the bug

After IOx upgraded DF recently, we hit a bug in count distinct with date_bin/date_part.

To Reproduce

After some investigation, here is the reproducer in Datafusion CLI:

create table t1(state string, city string, min_temp float, area int, time timestamp) as values 
    ('MA', 'Boston', 70.4, 1, 50),
    ('MA', 'Bedford', 71.59, 2, 150);

select date_part('year', time) as bla, count(distinct state) as count from t1 group by bla;
-- Optimizer rule 'single_distinct_aggregation_to_group_by' failed caused by Schema error: No field named "date_part(Utf8(""year""),t1.time)". Valid fields are group_alias_0, "COUNT(DISTINCT t1.state)".

-- this query has the same issue
select date_bin(interval '1 year', time) as bla, count(distinct state) as count from t1 group by bla;

Expected behavior

The queries should work

Additional context

After I backed out 15d8c9b locally, the queries work

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