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

AggregateProjectPullUpConstantsRule should not remove deterministic function group key if the function is dynamic

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Closed
    • Major
    • Resolution: Not A Problem
    • 1.21.0
    • 1.22.0
    • core

    Description

      Now AggregateProjectPullUpConstantsRule simplify the query:

      select hiredate
      from sales.emp
      where sal is null and hiredate = current_timestamp
      group by sal, hiredate
      having count(*) > 3
      

      from plan:

      LogicalProject(HIREDATE=[$1])
        LogicalFilter(condition=[>($2, 3)])
          LogicalAggregate(group=[{0, 1}], agg#0=[COUNT()])
            LogicalProject(SAL=[$5], HIREDATE=[$4])
              LogicalFilter(condition=[AND(IS NULL($5), =($4, CURRENT_TIMESTAMP))])
                LogicalTableScan(table=[[CATALOG, SALES, EMP]])
      

      to plan:

      LogicalProject(HIREDATE=[$1])
        LogicalFilter(condition=[>($2, 3)])
          LogicalProject(SAL=[$0], HIREDATE=[CURRENT_TIMESTAMP], $f2=[$1])
            LogicalAggregate(group=[{0}], agg#0=[COUNT()])
              LogicalProject(SAL=[$5], HIREDATE=[$4])
                LogicalFilter(condition=[AND(IS NULL($5), =($4, CURRENT_TIMESTAMP))])
                  LogicalTableScan(table=[[CATALOG, SALES, EMP]])
      

      which is unsafe, because for stream sql, we need to group data by dateTime, also the result is wrong if a batch job runs across days.

      Attachments

        Activity

          People

            danny0405 Danny Chen
            danny0405 Danny Chen
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Time Tracking

                Estimated:
                Original Estimate - Not Specified
                Not Specified
                Remaining:
                Remaining Estimate - 0h
                0h
                Logged:
                Time Spent - 2.5h
                2.5h