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

Stamatis Zampetakis commented on CALCITE-3245:
----------------------------------------------

Hey [~donnyzone], the complete test is already added in 
[https://github.com/apache/calcite/pull/1375] as I am in the middle of solving 
another problem.

> CompileException in Janino when a query contains a division between a Double 
> and a BigDecimal
> ---------------------------------------------------------------------------------------------
>
>                 Key: CALCITE-3245
>                 URL: https://issues.apache.org/jira/browse/CALCITE-3245
>             Project: Calcite
>          Issue Type: Bug
>          Components: core
>    Affects Versions: 1.20.0
>            Reporter: Stamatis Zampetakis
>            Priority: Major
>
> A CompileException in Janino is raised when the SQL query contains a division 
> operator between a column of type Double and a column of type BigDecimal.
> The following test added in {{ReflectiveSchemaTest}} can reproduce the 
> problem.
> {code:java}
> @Test public void testDivideDoubleBigDecimal() {
>     final CalciteAssert.AssertThat with =
>         CalciteAssert.that().withSchema("s", CATCHALL);
>     with.query("select \"wrapperDouble\" / \"bigDecimal\" as c\n"
>         + " from \"s\".\"everyTypes\"")
>         .runs();
>   }
> {code}
> The generated code is the following:
> {code:java}
> public org.apache.calcite.linq4j.Enumerable bind(final 
> org.apache.calcite.DataContext root) {
>   final org.apache.calcite.linq4j.Enumerable _inputEnumerable = 
> org.apache.calcite.linq4j.Linq4j.asEnumerable(((org.apache.calcite.test.ReflectiveSchemaTest.CatchallSchema)
>  ((org.apache.calcite.adapter.java.ReflectiveSchema) 
> root.getRootSchema().getSubSchema("s").unwrap(org.apache.calcite.adapter.java.ReflectiveSchema.class)).getTarget()).everyTypes);
>   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() {
>               return inputEnumerator.moveNext();
>             }
>             public void close() {
>               inputEnumerator.close();
>             }
>             public Object current() {
>               final org.apache.calcite.test.ReflectiveSchemaTest.EveryType 
> current = (org.apache.calcite.test.ReflectiveSchemaTest.EveryType) 
> inputEnumerator.current();
>               final Double inp15_ = current.wrapperDouble;
>               final java.math.BigDecimal inp21_ = current.bigDecimal;
>               return inp15_ == null || inp21_ == null ? 
> (java.math.BigDecimal) null : (java.math.BigDecimal) (inp15_.doubleValue() / 
> inp21_.doubleValue());
>             }
>           };
>       }
>     };
> }
> public Class getElementType() {
>   return java.math.BigDecimal.class;
> }
> {code}
> and the stack trace is given below:
> {noformat}
> Caused by: java.lang.RuntimeException: Error while compiling generated Java 
> code:
> ...
> 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:1110)
>       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)
>       ... 28 more
> Caused by: org.codehaus.commons.compiler.CompileException: Line 23, Column 
> 111: Cannot cast "double" to "java.math.BigDecimal"
>       at 
> org.codehaus.janino.UnitCompiler.compileError(UnitCompiler.java:12211)
>       at org.codehaus.janino.UnitCompiler.compileGet2(UnitCompiler.java:5051)
>       at org.codehaus.janino.UnitCompiler.access$8600(UnitCompiler.java:215)
>       at org.codehaus.janino.UnitCompiler$16.visitCast(UnitCompiler.java:4418)
>       at org.codehaus.janino.UnitCompiler$16.visitCast(UnitCompiler.java:4396)
>       at org.codehaus.janino.Java$Cast.accept(Java.java:4898)
>       at org.codehaus.janino.UnitCompiler.compileGet(UnitCompiler.java:4396)
>       at 
> org.codehaus.janino.UnitCompiler.compileGetValue(UnitCompiler.java:5662)
>       at org.codehaus.janino.UnitCompiler.compileGet2(UnitCompiler.java:4716)
>       at org.codehaus.janino.UnitCompiler.access$8800(UnitCompiler.java:215)
>       at 
> org.codehaus.janino.UnitCompiler$16.visitConditionalExpression(UnitCompiler.java:4420)
>       at 
> org.codehaus.janino.UnitCompiler$16.visitConditionalExpression(UnitCompiler.java:4396)
>       at org.codehaus.janino.Java$ConditionalExpression.accept(Java.java:4515)
>       at org.codehaus.janino.UnitCompiler.compileGet(UnitCompiler.java:4396)
>       at 
> org.codehaus.janino.UnitCompiler.compileGetValue(UnitCompiler.java:5662)
>       at org.codehaus.janino.UnitCompiler.compile2(UnitCompiler.java:2649)
>       at org.codehaus.janino.UnitCompiler.access$2800(UnitCompiler.java:215)
>       at 
> org.codehaus.janino.UnitCompiler$6.visitReturnStatement(UnitCompiler.java:1504)
>       at 
> org.codehaus.janino.UnitCompiler$6.visitReturnStatement(UnitCompiler.java:1487)
>       at org.codehaus.janino.Java$ReturnStatement.accept(Java.java:3563)
>       at org.codehaus.janino.UnitCompiler.compile(UnitCompiler.java:1487)
>       at 
> org.codehaus.janino.UnitCompiler.compileStatements(UnitCompiler.java:1567)
>       at org.codehaus.janino.UnitCompiler.compile(UnitCompiler.java:3388)
>       at 
> org.codehaus.janino.UnitCompiler.compileDeclaredMethods(UnitCompiler.java:1357)
>       at 
> org.codehaus.janino.UnitCompiler.compileDeclaredMethods(UnitCompiler.java:1330)
>       at org.codehaus.janino.UnitCompiler.compile2(UnitCompiler.java:822)
>       at org.codehaus.janino.UnitCompiler.compile2(UnitCompiler.java:981)
>       at org.codehaus.janino.UnitCompiler.compile2(UnitCompiler.java:951)
>       at org.codehaus.janino.UnitCompiler.access$200(UnitCompiler.java:215)
>       at 
> org.codehaus.janino.UnitCompiler$2.visitAnonymousClassDeclaration(UnitCompiler.java:409)
>       at 
> org.codehaus.janino.UnitCompiler$2.visitAnonymousClassDeclaration(UnitCompiler.java:406)
>       at 
> org.codehaus.janino.Java$AnonymousClassDeclaration.accept(Java.java:1149)
>       at org.codehaus.janino.UnitCompiler.compile(UnitCompiler.java:406)
>       at org.codehaus.janino.UnitCompiler.compileGet2(UnitCompiler.java:5509)
>       at org.codehaus.janino.UnitCompiler.access$9500(UnitCompiler.java:215)
>       at 
> org.codehaus.janino.UnitCompiler$16.visitNewAnonymousClassInstance(UnitCompiler.java:4432)
>       at 
> org.codehaus.janino.UnitCompiler$16.visitNewAnonymousClassInstance(UnitCompiler.java:4396)
>       at 
> org.codehaus.janino.Java$NewAnonymousClassInstance.accept(Java.java:5238)
>       at org.codehaus.janino.UnitCompiler.compileGet(UnitCompiler.java:4396)
>       at 
> org.codehaus.janino.UnitCompiler.compileGetValue(UnitCompiler.java:5662)
>       at org.codehaus.janino.UnitCompiler.compile2(UnitCompiler.java:2649)
>       at org.codehaus.janino.UnitCompiler.access$2800(UnitCompiler.java:215)
>       at 
> org.codehaus.janino.UnitCompiler$6.visitReturnStatement(UnitCompiler.java:1504)
>       at 
> org.codehaus.janino.UnitCompiler$6.visitReturnStatement(UnitCompiler.java:1487)
>       at org.codehaus.janino.Java$ReturnStatement.accept(Java.java:3563)
>       at org.codehaus.janino.UnitCompiler.compile(UnitCompiler.java:1487)
>       at 
> org.codehaus.janino.UnitCompiler.compileStatements(UnitCompiler.java:1567)
>       at org.codehaus.janino.UnitCompiler.compile(UnitCompiler.java:3388)
>       at 
> org.codehaus.janino.UnitCompiler.compileDeclaredMethods(UnitCompiler.java:1357)
>       at 
> org.codehaus.janino.UnitCompiler.compileDeclaredMethods(UnitCompiler.java:1330)
>       at org.codehaus.janino.UnitCompiler.compile2(UnitCompiler.java:822)
>       at org.codehaus.janino.UnitCompiler.compile2(UnitCompiler.java:981)
>       at org.codehaus.janino.UnitCompiler.compile2(UnitCompiler.java:951)
>       at org.codehaus.janino.UnitCompiler.access$200(UnitCompiler.java:215)
>       at 
> org.codehaus.janino.UnitCompiler$2.visitAnonymousClassDeclaration(UnitCompiler.java:409)
>       at 
> org.codehaus.janino.UnitCompiler$2.visitAnonymousClassDeclaration(UnitCompiler.java:406)
>       at 
> org.codehaus.janino.Java$AnonymousClassDeclaration.accept(Java.java:1149)
>       at org.codehaus.janino.UnitCompiler.compile(UnitCompiler.java:406)
>       at org.codehaus.janino.UnitCompiler.compileGet2(UnitCompiler.java:5509)
>       at org.codehaus.janino.UnitCompiler.access$9500(UnitCompiler.java:215)
>       at 
> org.codehaus.janino.UnitCompiler$16.visitNewAnonymousClassInstance(UnitCompiler.java:4432)
>       at 
> org.codehaus.janino.UnitCompiler$16.visitNewAnonymousClassInstance(UnitCompiler.java:4396)
>       at 
> org.codehaus.janino.Java$NewAnonymousClassInstance.accept(Java.java:5238)
>       at org.codehaus.janino.UnitCompiler.compileGet(UnitCompiler.java:4396)
>       at 
> org.codehaus.janino.UnitCompiler.compileGetValue(UnitCompiler.java:5662)
>       at org.codehaus.janino.UnitCompiler.compile2(UnitCompiler.java:2649)
>       at org.codehaus.janino.UnitCompiler.access$2800(UnitCompiler.java:215)
>       at 
> org.codehaus.janino.UnitCompiler$6.visitReturnStatement(UnitCompiler.java:1504)
>       at 
> org.codehaus.janino.UnitCompiler$6.visitReturnStatement(UnitCompiler.java:1487)
>       at org.codehaus.janino.Java$ReturnStatement.accept(Java.java:3563)
>       at org.codehaus.janino.UnitCompiler.compile(UnitCompiler.java:1487)
>       at 
> org.codehaus.janino.UnitCompiler.compileStatements(UnitCompiler.java:1567)
>       at org.codehaus.janino.UnitCompiler.compile(UnitCompiler.java:3388)
>       at 
> org.codehaus.janino.UnitCompiler.compileDeclaredMethods(UnitCompiler.java:1357)
>       at 
> org.codehaus.janino.UnitCompiler.compileDeclaredMethods(UnitCompiler.java:1330)
>       at org.codehaus.janino.UnitCompiler.compile2(UnitCompiler.java:822)
>       at org.codehaus.janino.UnitCompiler.compile2(UnitCompiler.java:432)
>       at org.codehaus.janino.UnitCompiler.access$400(UnitCompiler.java:215)
>       at 
> org.codehaus.janino.UnitCompiler$2.visitPackageMemberClassDeclaration(UnitCompiler.java:411)
>       at 
> org.codehaus.janino.UnitCompiler$2.visitPackageMemberClassDeclaration(UnitCompiler.java:406)
>       at 
> org.codehaus.janino.Java$PackageMemberClassDeclaration.accept(Java.java:1414)
>       at org.codehaus.janino.UnitCompiler.compile(UnitCompiler.java:406)
>       at org.codehaus.janino.UnitCompiler.compileUnit(UnitCompiler.java:378)
>       at org.codehaus.janino.SimpleCompiler.cook(SimpleCompiler.java:237)
>       at 
> org.codehaus.janino.SimpleCompiler.compileToClassLoader(SimpleCompiler.java:465)
>       at 
> org.codehaus.janino.ClassBodyEvaluator.compileToClass(ClassBodyEvaluator.java:313)
>       at 
> org.codehaus.janino.ClassBodyEvaluator.cook(ClassBodyEvaluator.java:235)
>       at org.codehaus.janino.SimpleCompiler.cook(SimpleCompiler.java:207)
>       at org.codehaus.commons.compiler.Cookable.cook(Cookable.java:50)
>       at 
> org.codehaus.janino.ClassBodyEvaluator.createInstance(ClassBodyEvaluator.java:347)
>       at 
> org.apache.calcite.adapter.enumerable.EnumerableInterpretable.getBindable(EnumerableInterpretable.java:162)
>       at 
> org.apache.calcite.adapter.enumerable.EnumerableInterpretable.toBindable(EnumerableInterpretable.java:125)
> {noformat}



--
This message was sent by Atlassian JIRA
(v7.6.14#76016)

Reply via email to