Uploaded image for project: 'IMPALA'
  1. IMPALA
  2. IMPALA-4336

Wrong results with nested union operands due to missing casts.

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Blocker
    • Resolution: Fixed
    • Affects Version/s: Impala 2.3.0, Impala 2.5.0, Impala 2.4.0, Impala 2.6.0, Impala 2.7.0
    • Fix Version/s: Impala 2.8.0
    • Component/s: Frontend
    • Labels:

      Description

      Unions with nested unions can produce incorrect results due to missing casts.
      This bug can happen for both UNION ALL and UNION DISTINCT.

      Repro:

      create table t (d double);
      insert into t values(5.5);
      
      select d from t union all values(cast(6.2 as float));
      +------------------------+
      | d                      |
      +------------------------+
      | 5.5                    |
      | 5.369229582389968e-315 |
      +------------------------+
      
      select d from t union all (select 10 union all select 20);
      +------------------------+
      | d                      |
      +------------------------+
      | 5.5                    |
      | 4.940656458412465e-323 |
      | 9.881312916824931e-323 |
      +------------------------+
      

      The underlying problem is that after unnesting unions we need to re-apply casts to the exprs of the unnested operands which my not be the same as the exprs of the original operand.

        Activity

        Hide
        alex.behm Alexander Behm added a comment -

        Michael Brown can the query generator create such queries? If not, we should consider adding the capability.

        Show
        alex.behm Alexander Behm added a comment - Michael Brown can the query generator create such queries? If not, we should consider adding the capability.
        Hide
        alex.behm Alexander Behm added a comment -

        commit 795c085fa38980085e830ce46ee8ccf298849dcb
        Author: Alex Behm <alex.behm@cloudera.com>
        Date: Fri Oct 21 18:58:36 2016 -0700

        IMPALA-4336: Cast exprs after unnesting union operands.

        The bug was that we cast the result exprs of operands before
        unnesting them. If we unnested an operands, casts were missing
        on those unnested operands' result exprs.

        The fix is to first unnest operands and then cast result exprs.

        Also clarifies the use of resultExprs vs. baseTblResultExprs.

        Change-Id: I5e3ab7349df7d67d0d9c2baf4a56342d3f04e76d
        Reviewed-on: http://gerrit.cloudera.org:8080/4815
        Reviewed-by: Alex Behm <alex.behm@cloudera.com>
        Tested-by: Internal Jenkins

        Show
        alex.behm Alexander Behm added a comment - commit 795c085fa38980085e830ce46ee8ccf298849dcb Author: Alex Behm <alex.behm@cloudera.com> Date: Fri Oct 21 18:58:36 2016 -0700 IMPALA-4336 : Cast exprs after unnesting union operands. The bug was that we cast the result exprs of operands before unnesting them. If we unnested an operands, casts were missing on those unnested operands' result exprs. The fix is to first unnest operands and then cast result exprs. Also clarifies the use of resultExprs vs. baseTblResultExprs. Change-Id: I5e3ab7349df7d67d0d9c2baf4a56342d3f04e76d Reviewed-on: http://gerrit.cloudera.org:8080/4815 Reviewed-by: Alex Behm <alex.behm@cloudera.com> Tested-by: Internal Jenkins

          People

          • Assignee:
            alex.behm Alexander Behm
            Reporter:
            alex.behm Alexander Behm
          • Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development