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

Inconsistent handling of COALESCE during validation

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Open
    • Major
    • Resolution: Unresolved
    • 1.36.0
    • None
    • core
    • None

    Description

      SqlCoalesceFunction has a rewriteCall() method which will replace the call with an SqlCase call during the unconditional rewrites stage.

      But expanding natural joins and USING conditions is done using COALESCE calls in a later validation stage.

      As a result, the following query:

      WITH A AS (SELECT 1 AS X)
        SELECT
          COALESCE(A0.X, A1.X),
          *
        FROM A AS A0 NATURAL JOIN A AS A1
      

      is transformed by the validation step into:

      WITH `A` AS (SELECT 1 AS `X`)
        SELECT
          CASE WHEN `A0`.`X` IS NOT NULL THEN `A0`.`X` ELSE `A1`.`X` END, 
          COALESCE(`A0`.`X`, `A1`.`X` AS `X0`) AS `X`
        FROM `A` AS `A0` NATURAL INNER JOIN `A` AS `A1`
      

      Maybe, the expanded results of * with natural joins and of USING should pass through unconditional rewrites at creation.

      Attachments

        Activity

          People

            Unassigned Unassigned
            cbrisson Claude Brisson
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated: