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

AggregateJoinTransposeRule generates inequivalent nodes if Aggregate relNode contains distinct aggregate function.

VotersWatch issueWatchersLinkCloneUpdate Comment AuthorReplace String in CommentUpdate Comment VisibilityDelete Comments
    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 1.19.0
    • Component/s: core
    • Labels:
      None

      Description

      AggregateJoinTransposeRule generates inequivalent nodes if Aggregate relNode contains distinct aggregate function.

      T1

      a (String) b (int)
      A 1
      A 2
      B 2
      C 3

       

      T2

      c(int)
      1
      1
      2

      For the following sql, 

      select count (distinct a) from t1, t2 where t1.b = t2.c  
      

      Aggregate would generate following node tree, which is inequivalent with original node tree.

      LogicalAggregate(group=[{}], EXPR$0=[$SUM0($4)])
      +- LogicalProject(b=[$0], EXPR$0=[$1], c=[$2], $f1=[$3], $f4=[*($1, $3)])
      +- LogicalJoin(condition=[=($0, $2)], joinType=[inner])
      :- LogicalAggregate(group=[\{1}], EXPR$0=[COUNT(DISTINCT $0)])
      : +- LogicalTableScan(table=[[t1]])
      +- LogicalAggregate(group=[\{0}], agg#0=[COUNT()])
      +- LogicalTableScan(table=[[t2]])
      

      Based on the converted plan, result is 4; while the correct answer is 2.

        Attachments

        Issue Links

          Activity

            People

            • Assignee:
              julianhyde Julian Hyde
              Reporter:
              jinyu.zj Jing Zhang

              Dates

              • Created:
                Updated:
                Resolved:

                Issue deployment