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

Non-RexInputRef may fails the matching of FilterToProjectUnifyRule during 'invert' by mistake.

    XMLWordPrintableJSON

Details

    Description

      In current code of FilterToProjectUnifyRule::invert(https://github.com/apache/calcite/blob/master/core/src/main/java/org/apache/calcite/plan/SubstitutionVisitor.java#L1124), the implementation
      1. Fails the matching when there is Non-RexInputRef in the projects
      2. Didn't check if all items of exprList has already been set correctly.
      As a result below tests fails.

        @Test public void testFilterToProject0() {
          String union =
              "select * from \"emps\" where \"empid\" > 300\n"
                  + "union all select * from \"emps\" where \"empid\" < 200";
          String mv = "select *, \"empid\" * 2 from (" + union + ")";
          String query = "select * from (" + union + ") where (\"empid\" * 2) > 3";
          checkMaterialize(mv, query);
        }
      
        @Test public void testFilterToProject1() {
          String agg =
              "select \"deptno\", count(*) as \"c\", sum(\"salary\") as \"s\"\n"
                  + "from \"emps\" group by \"deptno\"";
          String mv = "select \"c\", \"s\", \"s\" from (" + agg + ")";
          String query = "select * from (" + agg + ") where (\"s\" * 0.8) > 10000";
          checkNoMaterialize(mv, query, HR_FKUK_MODEL);
        }
      

      Attachments

        Issue Links

          Activity

            People

              jinxing6042@126.com Jin Xing
              jinxing6042@126.com Jin Xing
              Votes:
              0 Vote for this issue
              Watchers:
              3 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 - 1h 20m
                  1h 20m