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

RelStructuredTypeFlattener produces bad plan for single field struct

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 1.23.0, 1.28.0, 1.33.0
    • 1.35.0
    • core

    Description

      A Beam user brought us a query that produces an invalid plan after
      upgrading to a newer version of Beam (moving them from Calcite 1.20 to
      1.28). I was able to write a test case which demonstrates this issue
      with a trivial filter on a table containing a nested struct with a
      single field. The issue appears to be coming out of
      RelStructuredTypeFlattener.rewrite and I bisected it to a single
      commit, e44beba28.

      Removing the noFlatteningForInput function added in this commit fixes
      the issue. That method doesn't appear to be looking at types at all,
      only mismatches in field count, I expect so any single field struct
      would hit this. Any suggestions on how we can work around this in
      Beam?

      The test query and plans are as follows, the test case is in PR 3092.

      select dn.skill from sales.dept_single dn WHERE dn.skill.type = ''
      

      Expected plan:

      LogicalProject(SKILL=[ROW($0)])
        LogicalFilter(condition=[=($0, '')])
          LogicalProject(TYPE=[$0.TYPE])
            LogicalTableScan(table=[[CATALOG, SALES, DEPT_SINGLE]])
      

      Actual Plan:

      LogicalProject(SKILL=[ROW($0)])
        LogicalFilter(condition=[=($0.TYPE, '')])
          LogicalProject(TYPE=[$0.TYPE])
            LogicalTableScan(table=[[CATALOG, SALES, DEPT_SINGLE]])
      

      Plan before flatten:

      LogicalProject(SKILL=[$0])
        LogicalFilter(condition=[=($0.TYPE, '')])
          LogicalTableScan(table=[[CATALOG, SALES, DEPT_SINGLE]])
      

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              apilloud Andrew Pilloud
              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 - 1h 50m
                  1h 50m