[ 
https://issues.apache.org/jira/browse/CALCITE-2731?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Zoltan Haindrich updated CALCITE-2731:
--------------------------------------
    Description: 
In CALCITE-1413 we were cautious to not simplify 
{code}
CASE a=0 THEN 0 ELSE 1/a END
{code}
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:
{code}
CASE $1 THEN $2 ELSE $3 END
{code}

testcase for conditions.iq:
{code}
with ax(s) as (values (1),(0))
select case when s=0 then false else 100/s > 0 end from ax;

!ok
{code}

resulting exception:
{code}
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)
{code}


  was:
In CALCITE-1413 we were cautious to not simplify 
{code}
CASE a=0 THEN 0 ELSE 1/a END
{code}
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:
{code}
CASE $1 THEN $2 ELSE $3 END
{code}



> Case statements are simplified with unsafe conditions
> -----------------------------------------------------
>
>                 Key: CALCITE-2731
>                 URL: https://issues.apache.org/jira/browse/CALCITE-2731
>             Project: Calcite
>          Issue Type: Bug
>            Reporter: Zoltan Haindrich
>            Assignee: Zoltan Haindrich
>            Priority: Major
>
> In CALCITE-1413 we were cautious to not simplify 
> {code}
> CASE a=0 THEN 0 ELSE 1/a END
> {code}
> 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:
> {code}
> CASE $1 THEN $2 ELSE $3 END
> {code}
> testcase for conditions.iq:
> {code}
> with ax(s) as (values (1),(0))
> select case when s=0 then false else 100/s > 0 end from ax;
> !ok
> {code}
> resulting exception:
> {code}
> 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)
> {code}



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to