[ 
https://issues.apache.org/jira/browse/CALCITE-2535?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16610214#comment-16610214
 ] 

Hongze Zhang edited comment on CALCITE-2535 at 9/11/18 7:47 AM:
----------------------------------------------------------------

[~vladimirsitnikov]
{quote}select coalesce(case when count(\*)>0 then 1 else null end, 0/0) from 
values(1)
{quote}
Thank you for this case. I got what you mean.
 In current version of Calcite this SQL runs to failure (no matter an error or 
an exception), which is not good. IMO lazy initializing the folded constant 
(PR# 821) solves this problem, see the generated code:
{code:java}
public Object current() {
  final boolean v = 
org.apache.calcite.runtime.SqlFunctions.toLong(inputEnumerator.current()) > 0L;
  return v ? (v ? Integer.valueOf(1) : (Integer) null) : (Integer) (Integer) 
$L4J$C$Integer_valueOf_int_Integer_0_0_get_.get();
}

static final com.google.common.base.Supplier $L4J$C$0_0 = 
com.google.common.base.Suppliers.memoize(new com.google.common.base.Supplier(){
  public Integer get() {
        return 0 / 0;
  }

});
static final com.google.common.base.Supplier 
$L4J$C$Integer_valueOf_int_Integer_0_0_get_ = 
com.google.common.base.Suppliers.memoize(new com.google.common.base.Supplier(){
  public Integer get() {
        return Integer.valueOf((int) (Integer) $L4J$C$0_0.get());
  }

});
{code}

The generated code will be safer since all calculations will be triggered from 
invocation of Enumerator#current.


was (Author: zhztheplayer):
[~vladimirsitnikov]
{quote}select coalesce(case when count(\*)>0 then 1 else null end, 0/0) from 
values(1)
{quote}
Thank you for this case. I got what you mean.
 In current version of Calcite this SQL runs to failure (no matter an error or 
an exception), which is not good. IMH lazy initializing the folded constant 
(PR# 821) solves this problem, see the generated code:
{code:java}
public Object current() {
  final boolean v = 
org.apache.calcite.runtime.SqlFunctions.toLong(inputEnumerator.current()) > 0L;
  return v ? (v ? Integer.valueOf(1) : (Integer) null) : (Integer) (Integer) 
$L4J$C$Integer_valueOf_int_Integer_0_0_get_.get();
}

static final com.google.common.base.Supplier $L4J$C$0_0 = 
com.google.common.base.Suppliers.memoize(new com.google.common.base.Supplier(){
  public Integer get() {
        return 0 / 0;
  }

});
static final com.google.common.base.Supplier 
$L4J$C$Integer_valueOf_int_Integer_0_0_get_ = 
com.google.common.base.Suppliers.memoize(new com.google.common.base.Supplier(){
  public Integer get() {
        return Integer.valueOf((int) (Integer) $L4J$C$0_0.get());
  }

});
{code}

The generated code will be safer since all calculations will be triggered from 
invocation of Enumerator#current.

> Runtime failure check not working in SqlTesterImpl.java
> -------------------------------------------------------
>
>                 Key: CALCITE-2535
>                 URL: https://issues.apache.org/jira/browse/CALCITE-2535
>             Project: Calcite
>          Issue Type: Bug
>          Components: core
>            Reporter: Hongze Zhang
>            Assignee: Julian Hyde
>            Priority: Major
>
> Problem at SqlTesterImpl#checkFails:
> When argument "runtime" is specified as true, error assertion and error 
> message matching will not be performed.
> This issue could result in wrong test result in SqlOperatorBaseTest.



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

Reply via email to