Uploaded image for project: 'Calcite'
  1. Calcite
  2. CALCITE-2907

AggregateExpandDistinctAggregatesRule produces a wrong relational algebra

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Invalid
    • 1.18.0
    • None
    • core
    • None

    Description

      In my usecase:

      an Aggregate which contains distinct call was converted improperly to  a wrong relational algebra.

       

      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
      

       

       

      After digging into the code,I found at the line 444 of the AggregateExpandDistinctAggregatesRule.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 {
      

      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.

       

       

      Attachments

        Activity

          People

            Unassigned Unassigned
            hhlai1990 Lai Zhou
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: