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

RelToSqlConverter fails to convert correlated lateral joins

    XMLWordPrintableJSON

Details

    Description

       

      input query:

      SELECT 
        "a", "x"
      FROM 
        "myDb"."myTable",
        unnest("xs") as "x"; 

      schema:

      https://github.com/MasseGuillaume/calcite/blob/0126e6cfa47061886b2012ad2d2c32408455ae88/testkit/src/main/java/org/apache/calcite/test/CalciteAssert.java#L2180-L2211

      myTable(
          a: BIGINT,
          // ...
          xs: ARRAY<BIGINT>,
          // ...
      ) 
      

      logical plan:

      LogicalProject(a=[$0], x=[$6])
        LogicalCorrelate(correlation=[$cor0], joinType=[inner], requiredColumns=[{4}])
          LogicalProject(a=[$0], b=[$1.n11.b], c=[$1.n12.c], d=[$2.d], xs=[$3], e=[$4])
            LogicalTableScan(table=[[myDb, myTable]])
          Uncollect
            LogicalProject(xs=[$cor0.xs])
              LogicalValues(tuples=[[{ 0 }]])
      

      obtained sql:

       

      SELECT
        "$cor0"."a",
        "$cor0"."xs0" AS "x" -- <-- xs0 ?
      FROM 
        (
          SELECT "a", "n1"."n11"."b", "n1"."n12"."c", "n2"."d", "xs", "e" FROM "myDb"."myTable"
        ) AS "$cor0",
        LATERAL UNNEST (
         SELECT "$cor0"."xs" FROM (VALUES (0)) AS "t" ("ZERO")
        ) AS "t1" ("xs") AS "t10"
      

      I would expect the query to be converted to something close to the original query. Here "xs0" does not exists.

       

      https://github.com/MasseGuillaume/calcite/commit/0126e6cfa47061886b2012ad2d2c32408455ae88

      Attachments

        Activity

          People

            Unassigned Unassigned
            MasseGuillaume Guillaume Massé
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: