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

RexProgramBuilder makes unsafe simplifications to CASE expressions

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 1.18.0
    • Component/s: None
    • Labels:
      None

      Description

      In CALCITE-1413 we were cautious to not simplify

      CASE a=0 THEN 0 ELSE 1/a END
      

      and it seemed good; however: RexProgramBuilder is also invokes simplify - but the protection at that point is not able to work, because it sees only references:

      CASE $1 THEN $2 ELSE $3 END
      

      testcase for conditions.iq:

      with ax(s) as (values (1),(0))
      select case when s=0 then false else 100/s > 0 end from ax;
      
      !ok
      

      resulting exception:

      java.lang.AssertionError: Files differ: /home/kirk/projects/calcite/core/target/test-classes/sql/surefire/sql/conditions.iq /home/kirk/projects/calcite/core/target/test-classes/sql/conditions.iq
      277a278,326
      > Error while executing command OkCommand [sql: with ax(s) as (values (1),(0))
      > select case when s=0 then false else 100/s > 0 end from ax]
      > java.lang.ArithmeticException: / by zero
      > 	at Baz$1$1.current(Unknown Source)
      > 	at org.apache.calcite.linq4j.Linq4j$EnumeratorIterator.next(Linq4j.java:683)
      > 	at org.apache.calcite.avatica.util.IteratorCursor.next(IteratorCursor.java:46)
      

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                kgyrtkirk Zoltan Haindrich
                Reporter:
                kgyrtkirk Zoltan Haindrich
              • Votes:
                0 Vote for this issue
                Watchers:
                2 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: