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

Column names in materialization do not match

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Reopened
    • Minor
    • Resolution: Unresolved
    • 1.27.0
    • None
    • core
    • None

    Description

      Original subject: "MaterializedViewAggregateRule should not rewrite top level name alias in project".

      We use MaterializedViewAggregateRule to do optimize. 

      the original sql is : 

      SELECT (intDiv(ts/1000, 60) * 60) * 1000 as t, source_idc, dest_idc, sum(jitter200)/sum(total) as `jitter200_rate` FROM metricsdb.test_table WHERE ts/1000 >= 1627874961 AND source_idc in ('xxx') AND dest_idc IN ('xxx') GROUP BY t,source_idc,dest_idc ORDER BY t
      

      after optimize, the sql is : 

      SELECT `intDiv`(`ts` / 1000, 60) * 60 * 1000 AS `$f14`, `source_idc`, `dest_idc`, SUM(`jitter200`) / SUM(`total`) AS `$f3` FROM `metricsdb`.`s2s_idc2idc_jitter_mv_all` WHERE `ts` / 1000 >= 1627874961 AND `source_idc` IN ('xxx') AND `dest_idc` IN ('xxx') GROUP BY `source_idc`, `dest_idc`, `intDiv`(`ts` / 1000, 60) * 60 * 1000 ORDER BY `intDiv`(`ts` / 1000, 60) * 60 * 1000
      

      we expected it to be : 

      `intDiv`(`ts` / 1000, 60) * 60 * 1000 AS `t`

      , not

      `intDiv`(`ts` / 1000, 60) * 60 * 1000 AS `$f14`

       

      After examine the code , we found in  rewriteView of MaterializedViewAggregateRule

          return relBuilder
              .project(rewrittenExprs)
              .convert(topRowType, false) // this means do not compare the names.
              .build();
      

      when change it to true, everything goes as expected.

       

      I think the rewrite rule should maintain then same type and name , not just type.  

       

      If it's true, we can come up with some modification and tests.

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              Enze Enze Liu
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated: