[ https://issues.apache.org/jira/browse/CALCITE-2907?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Lai Zhou closed CALCITE-2907. ----------------------------- Resolution: Invalid > AggregateExpandDistinctAggregatesRule produces a wrong relational algebra > ------------------------------------------------------------------------- > > Key: CALCITE-2907 > URL: https://issues.apache.org/jira/browse/CALCITE-2907 > Project: Calcite > Issue Type: Bug > Components: core > Affects Versions: 1.18.0 > Reporter: Lai Zhou > Priority: Major > > In my usecase: > an Aggregate which contains distinct call was converted improperly to a > wrong relational algebra. > > {code:java} > SELECT user_id, > order_id, > product_id, > count(DISTINCT secured_libs.u51decrypt(phone)) AS > contact_count, > stddev_pop(secured_libs.u51decrypt(phone)) AS > seg3stddev, > entropy(secured_libs.u51decrypt(phone)) AS > seg3entropy > FROM dw_risk__mygravitation_v_snap_contacts_contacts > GROUP BY user_id, > order_id, > product_id > {code} > > > After digging into the code,I found at the line 444 of the > AggregateExpandDistinctAggregatesRule.java : > > {code:java} > int x = groupCount; > final List<AggregateCall> newCalls = new ArrayList<>(); > for (AggregateCall aggCall : aggregate.getAggCallList()) { > final int newFilterArg; > final List<Integer> newArgList; > final SqlAggFunction aggregation; > if (!aggCall.isDistinct()) { > aggregation = SqlStdOperatorTable.MIN; > newArgList = ImmutableIntList.of(x++); > newFilterArg = filters.get(aggregate.getGroupSet()); > } else { > {code} > the undistinct aggregate call `stddev_pop` and `entropy` was converted to a > SqlStdOperatorTable.MIN,(actually all undistinct aggregate call here will be > converted to a SqlStdOperatorTable.MIN ). > I don't understand how it works. > I guess someone made a faulty assumption here. [~julianhyde] ,can someone > help me ASAP ? > It’s very important for my business. > > -- This message was sent by Atlassian JIRA (v7.6.3#76005)