doris icon indicating copy to clipboard operation
doris copied to clipboard

[Enhancement] support distinct in analytic functions

Open morrySnow opened this issue 1 year ago • 4 comments

Search before asking

  • [X] I had searched in the issues and found no similar issues.

Description

create table t(id int, c1 int, c2 double, c3 string) properties('replication_num'='1');

support distinct in analytic functions: count, sum and avg

select c1, c2, avg( distinct c1) over(partition by c2) from t;

Solution

  1. remove restirct of distinct in analytic functions 1.1. https://github.com/apache/doris/blob/543576227db1521e66c2d32a6fa522c1a7a7aa61/fe/fe-core/src/main/java/org/apache/doris/nereids/parser/LogicalPlanBuilder.java#L2140-L2145 1.2. https://github.com/apache/doris/blob/543576227db1521e66c2d32a6fa522c1a7a7aa61/fe/fe-core/src/main/java/org/apache/doris/nereids/parser/LogicalPlanBuilder.java#L2155-L2160
  2. convert functions to distinct one in ExtractAndNormalizeWindowExpression 2.1. count(distinct c1) over(partition c2) to multi_distinct_count(c1) over(partition c2) 2.2. sum(distinct c1) over(partition c2) to multi_distinct_sum(c1) over(partition c2) 2.3. avg(distinct c1) over(partition c2) to cast(multi_distinct_sum(c1) over(partition c2) as double) / cast(multi_distinct_count(c1) over(partition c2) as double)

Are you willing to submit PR?

  • [ ] Yes I am willing to submit a PR!

Code of Conduct

morrySnow avatar Jun 26 '24 12:06 morrySnow

I want to try 2.1

cjj2010 avatar Jun 27 '24 02:06 cjj2010

@cjj2010 This issue cannot be split into smaller tasks for solving. Can you handle the entire issue?

morrySnow avatar Jun 27 '24 06:06 morrySnow

@cjj2010 This issue cannot be split into smaller tasks for solving. Can you handle the entire issue?

Okay, I am willing to handle the entire issue. The business scenario I am currently facing requires this feature very much

cjj2010 avatar Jun 29 '24 03:06 cjj2010

@cjj2010 Great! I will assign this issue to you

morrySnow avatar Jul 01 '24 09:07 morrySnow

We're closing this issue because it hasn't been updated in a while. If you'd like to revive this issue, please reopen it and feel free a maintainer to remove the Stale tag!

github-actions[bot] avatar Sep 12 '25 00:09 github-actions[bot]