You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@calcite.apache.org by "Rui Wang (Jira)" <ji...@apache.org> on 2019/11/26 18:07:00 UTC

[jira] [Comment Edited] (CALCITE-3536) Fix "if(null)" not compiling in CoalesceImplementor

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

Rui Wang edited comment on CALCITE-3536 at 11/26/19 6:06 PM:
-------------------------------------------------------------

I changed the JIRA title to reflect what is wrong: null cannot be used as a bool in a if(). 


was (Author: amaliujia):
I changed the JIRA title to reflect what is wrong: null cannot be put in a if().

> Fix "if(null)" not compiling in CoalesceImplementor
> ---------------------------------------------------
>
>                 Key: CALCITE-3536
>                 URL: https://issues.apache.org/jira/browse/CALCITE-3536
>             Project: Calcite
>          Issue Type: Bug
>            Reporter: Jin Xing
>            Priority: Major
>              Labels: pull-request-available
>          Time Spent: 2h 10m
>  Remaining Estimate: 0h
>
> Currently, COALESCE expression specified in sql string will be rewrite to CASE by SqlValidator [1], thus CoalesceImplementor is almost no use. But it is actually used somewhere, for example Sum0Splitter. When running AggregateRemove and split expression SUM0, a COALESCE is actually created and no chance to be rewrite to CASE anymore.
> In current code, CoalesceImplementor doesn't handle NullAs properly by semantics.
> If we disable the rewrite from COALESCE to CASE in Validator and run below sql in JDBC Test:
> {code:java}
> select grocery_sqft from store where coalesce(grocery_sqft, 0) >= 20000{code}
> We will get below exception: 
> {code:java}
> Caused by: java.lang.RuntimeException: Error while compiling generated Java code:
> public org.apache.calcite.linq4j.Enumerable bind(final org.apache.calcite.DataContext root) {
>   final org.apache.calcite.linq4j.Enumerable _inputEnumerable = org.apache.calcite.schema.Schemas.queryable(root, root.getRootSchema().getSubSchema("foodmart2"), java.lang.Object[].class, "store").asEnumerable();
>   return new org.apache.calcite.linq4j.AbstractEnumerable(){
>       public org.apache.calcite.linq4j.Enumerator enumerator() {
>         return new org.apache.calcite.linq4j.Enumerator(){
>             public final org.apache.calcite.linq4j.Enumerator inputEnumerator = _inputEnumerable.enumerator();
>             public void reset() {
>               inputEnumerator.reset();
>             }            public boolean moveNext() {
>               while (inputEnumerator.moveNext()) {
>                 final Integer inp16_ = (Integer) ((Object[]) inputEnumerator.current())[16];
>                 if ((inp16_ ? inp16_.intValue() : 0) >= 20000) {
>                   return true;
>                 }
>               }
>               return false;
>             }            public void close() {
>               inputEnumerator.close();
>             }            public Object current() {
>               return (Integer) ((Object[]) inputEnumerator.current())[16];
>             }          };
>       }    };
> } 
> at org.apache.calcite.avatica.Helper.wrap(Helper.java:37) 
> at org.apache.calcite.avatica.Helper.wrap(Helper.java:37) 
> at org.apache.calcite.adapter.enumerable.EnumerableInterpretable.toBindable(EnumerableInterpretable.java:128) at org.apache.calcite.prepare.CalcitePrepareImpl$CalcitePreparingStmt.implement(CalcitePrepareImpl.java:1111) at org.apache.calcite.prepare.Prepare.prepareSql(Prepare.java:332) 
> at org.apache.calcite.prepare.Prepare.prepareSql(Prepare.java:231) 
> at org.apache.calcite.prepare.CalcitePrepareImpl.prepare2_(CalcitePrepareImpl.java:638) 
> at org.apache.calcite.prepare.CalcitePrepareImpl.prepare_(CalcitePrepareImpl.java:502) 
> at org.apache.calcite.prepare.CalcitePrepareImpl.prepareSql(CalcitePrepareImpl.java:472) 
> at org.apache.calcite.jdbc.CalciteConnectionImpl.parseQuery(CalciteConnectionImpl.java:231) 
> at org.apache.calcite.jdbc.CalciteMetaImpl.prepareAndExecute(CalciteMetaImpl.java:550) 
> at org.apache.calcite.avatica.AvaticaConnection.prepareAndExecuteInternal(AvaticaConnection.java:675) 
> at org.apache.calcite.avatica.AvaticaStatement.executeInternal(AvaticaStatement.java:156) ... 29 more
> Caused by: org.codehaus.commons.compiler.CompileException: Line 14, Column 28: Not a boolean expression 
> at org.codehaus.janino.UnitCompiler.compileError(UnitCompiler.java:12211) 
> at org.codehaus.janino.UnitCompiler.compileBoolean2(UnitCompiler.java:3994) 
> at org.codehaus.janino.UnitCompiler.access$6300(UnitCompiler.java:215){code}
> This issue was found when I try to resolve CALCITE-3124 and CALCITE-3505
> [1] [https://github.com/apache/calcite/blob/master/core/src/main/java/org/apache/calcite/sql/validate/SqlValidatorImpl.java#L1210]



--
This message was sent by Atlassian Jira
(v8.3.4#803005)