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

Case expression with constant condition generates IllegalStateException

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Critical
    • Resolution: Fixed
    • Affects Version/s: Impala 2.9.0
    • Fix Version/s: Impala 2.9.0
    • Component/s: Frontend
    • Labels:
      None

      Description

      The following SQLs generate an IllegalStateException:

      select distinct case when true then id else 0 end from functional.alltypes;
      select case when true then id else 0 end from functional.alltypes group by id;

      These SQLs do not produce an error:

      select distinct case when true then 0 else id end from functional.alltypes;
      select distinct case when id=id then id else 0 end from functional.alltypes;
      select case when true then id else 0 end from functional.alltypes;

      This seems to be related to the optimization for case expressions with a constant condition interacting with distinct.

        Activity

        Hide
        twmarshall Thomas Tauber-Marshall added a comment -

        commit 3edc9099bcd1b2e962c83575bbb38155b77b780e
        Author: Thomas Tauber-Marshall <tmarshall@cloudera.com>
        Date: Mon Feb 6 12:46:18 2017 -0800

        IMPALA-4849: IllegalStateException from rewritten CASE expr

        In SelectList.reset(), we call reset() on each select list item's
        expr. reset() is supposed to remove implicit casts, by returning
        the reset expr with implicit cast exprs removed from the tree.

        Previously SelectList.reset() ignored the return value of the calls
        to Expr.reset(), meaning that if the top-most expr of the select list
        item is an implicit cast, it won't actually get removed, which causes
        problems with analysis since implicit casts are always treated as
        pre-analyzed.

        The solution is to set the select list item's exprs to the return
        value of reset().

        Testing:

        • Added a regression test to exprs.test

        Change-Id: I16ff88716b185e1d72d2bc603a42bd06c60ec18e
        Reviewed-on: http://gerrit.cloudera.org:8080/5917
        Reviewed-by: Alex Behm <alex.behm@cloudera.com>
        Tested-by: Impala Public Jenkins

        Show
        twmarshall Thomas Tauber-Marshall added a comment - commit 3edc9099bcd1b2e962c83575bbb38155b77b780e Author: Thomas Tauber-Marshall <tmarshall@cloudera.com> Date: Mon Feb 6 12:46:18 2017 -0800 IMPALA-4849 : IllegalStateException from rewritten CASE expr In SelectList.reset(), we call reset() on each select list item's expr. reset() is supposed to remove implicit casts, by returning the reset expr with implicit cast exprs removed from the tree. Previously SelectList.reset() ignored the return value of the calls to Expr.reset(), meaning that if the top-most expr of the select list item is an implicit cast, it won't actually get removed, which causes problems with analysis since implicit casts are always treated as pre-analyzed. The solution is to set the select list item's exprs to the return value of reset(). Testing: Added a regression test to exprs.test Change-Id: I16ff88716b185e1d72d2bc603a42bd06c60ec18e Reviewed-on: http://gerrit.cloudera.org:8080/5917 Reviewed-by: Alex Behm <alex.behm@cloudera.com> Tested-by: Impala Public Jenkins

          People

          • Assignee:
            twmarshall Thomas Tauber-Marshall
            Reporter:
            joemcdonnell Joe McDonnell
          • Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development