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

Simplify CASE P1 THEN <boolean> P@ THEN <booleans> ... ELSE TRUE/FALSE

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Open
    • Minor
    • Resolution: Unresolved
    • None
    • None
    • core
    • None

    Description

      In HIVE-14431 jcamachorodriguez proposed a simplification for CASE when all branches are not nullable boolean expression into an alternative AND/OR/NOT based expression. This allows for more aggressive reductions and split/push-down on the whole. Meantime the simplifier code migrated to Calcite so I'm reviving this here.

      The proposed simplification is:

      CASE
      WHEN p1 THEN ex1
      WHEN p2 THEN ex2
      ...
      WHEN pn THEN exn
      ELSE TRUE/FALSE
      END
      

      to be transformed into:

      (p1 AND ex1)
      OR (not(p1) AND p2 AND x2)
      ...
      OR (not(p1) AND not(p2) ... AND not(pn-1) AND Pn AND exn)
      [OR (not(p1) AND not(p2) ... AND not(pn))]
      

      The last OR is depending on the ELSE branch being TRUE/FALSE.

      Attachments

        Issue Links

          Activity

            People

              rusanu Remus Rusanu
              rusanu Remus Rusanu
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated: