You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@calcite.apache.org by "xuyangzhong (Jira)" <ji...@apache.org> on 2021/09/28 09:54:00 UTC

[jira] [Created] (CALCITE-4810) Failed to cast a double field (which isn't a literal) to boolean in the test case.

xuyangzhong created CALCITE-4810:
------------------------------------

             Summary: Failed to cast a double field (which isn't a literal) to boolean in the test case.
                 Key: CALCITE-4810
                 URL: https://issues.apache.org/jira/browse/CALCITE-4810
             Project: Calcite
          Issue Type: Bug
            Reporter: xuyangzhong


The cause of this matter is that when I add a test case in SqlOperatorBaseTest:
{code:java}
// code placeholder
  @Test void myTest(){
    tester.checkBoolean("cast(0.1e0 as boolean)",false);
  }
{code}
The tester will turn the single sql to these two SQLs which will be all tested:
{code:java}
// SQL 1 
values (cast(0.1e0 as boolean))

// SQL 2
select cast(p0 as boolean) from (values (0.1e0)) as t(p0)
{code}
The SQL1 passed by the RexSimplify. But The SQL2 throws a exception following:
{code:java}
// code placeholder
java.sql.SQLException: Error while executing SQL "select cast(p0 as boolean) from (values (0.1e0)) as t(p0)": 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.linq4j.Linq4j.asEnumerable(new Double[] {
        0.1D});
      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() {
                  return (boolean) org.apache.calcite.runtime.SqlFunctions.toDouble(inputEnumerator.current());
                }
    
              };
          }
    
        };
    }
    
    
    public Class getElementType() {
      return boolean.class;
    }
    
    
    
        at org.apache.calcite.avatica.Helper.createException(Helper.java:56)
        at org.apache.calcite.avatica.Helper.createException(Helper.java:41)
        at org.apache.calcite.avatica.AvaticaStatement.executeInternal(AvaticaStatement.java:163)
        at org.apache.calcite.avatica.AvaticaStatement.executeQuery(AvaticaStatement.java:227)
        at org.apache.calcite.sql.test.SqlOperatorBaseTest$TesterImpl.check(SqlOperatorBaseTest.java:10371)
        at org.apache.calcite.sql.test.AbstractSqlTester.check(AbstractSqlTester.java:464)
        at org.apache.calcite.sql.test.AbstractSqlTester.checkBoolean(AbstractSqlTester.java:433)
        at org.apache.calcite.sql.test.SqlOperatorBaseTest.myTest(SqlOperatorBaseTest.java:1619)
        at org.junit.platform.commons.util.ReflectionUtils.invokeMethod(ReflectionUtils.java:675)
        at org.junit.jupiter.engine.execution.MethodInvocation.proceed(MethodInvocation.java:60)
        at org.junit.jupiter.engine.execution.InvocationInterceptorChain$ValidatingInvocation.proceed(InvocationInterceptorChain.java:125)
        at org.junit.jupiter.engine.extension.TimeoutInvocation.proceed(TimeoutInvocation.java:46)
        at org.junit.jupiter.engine.extension.TimeoutExtension.intercept(TimeoutExtension.java:139)
        at org.junit.jupiter.engine.extension.TimeoutExtension.interceptTestableMethod(TimeoutExtension.java:131)
        at org.junit.jupiter.engine.extension.TimeoutExtension.interceptTestMethod(TimeoutExtension.java:81)
        at org.junit.jupiter.engine.execution.ExecutableInvoker$ReflectiveInterceptorCall.lambda$ofVoidMethod$0(ExecutableInvoker.java:115)
        at org.junit.jupiter.engine.execution.ExecutableInvoker.lambda$invoke$0(ExecutableInvoker.java:105)
        at org.junit.jupiter.engine.execution.InvocationInterceptorChain$InterceptedInvocation.proceed(InvocationInterceptorChain.java:104)
        at org.junit.jupiter.engine.execution.InvocationInterceptorChain.proceed(InvocationInterceptorChain.java:62)
        at org.junit.jupiter.engine.execution.InvocationInterceptorChain.chainAndInvoke(InvocationInterceptorChain.java:43)
        at org.junit.jupiter.engine.execution.InvocationInterceptorChain.invoke(InvocationInterceptorChain.java:35)
        at org.junit.jupiter.engine.execution.ExecutableInvoker.invoke(ExecutableInvoker.java:104)
        at org.junit.jupiter.engine.execution.ExecutableInvoker.invoke(ExecutableInvoker.java:98)
        at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.lambda$invokeTestMethod$6(TestMethodTestDescriptor.java:202)
        at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
        at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.invokeTestMethod(TestMethodTestDescriptor.java:198)
        at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.execute(TestMethodTestDescriptor.java:135)
        at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.execute(TestMethodTestDescriptor.java:69)
        at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$5(NodeTestTask.java:135)
        at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
        at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$7(NodeTestTask.java:125)
        at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:135)
        at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:123)
        at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
        at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:122)
        at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:80)
        at org.junit.platform.engine.support.hierarchical.ForkJoinPoolHierarchicalTestExecutorService$ExclusiveTask.compute(ForkJoinPoolHierarchicalTestExecutorService.java:171)
        at org.junit.platform.engine.support.hierarchical.ForkJoinPoolHierarchicalTestExecutorService.invokeAll(ForkJoinPoolHierarchicalTestExecutorService.java:115)
        at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$5(NodeTestTask.java:139)
        at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
        at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$7(NodeTestTask.java:125)
        at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:135)
        at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:123)
        at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
        at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:122)
        at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:80)
        at org.junit.platform.engine.support.hierarchical.ForkJoinPoolHierarchicalTestExecutorService$ExclusiveTask.compute(ForkJoinPoolHierarchicalTestExecutorService.java:171)
        at org.junit.platform.engine.support.hierarchical.ForkJoinPoolHierarchicalTestExecutorService.invokeAll(ForkJoinPoolHierarchicalTestExecutorService.java:115)
        at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$5(NodeTestTask.java:139)
        at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
        at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$7(NodeTestTask.java:125)
        at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:135)
        at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:123)
        at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
        at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:122)
        at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:80)
        Next exception 1: [CIRCULAR REFERENCE SQLException]
        Next exception 2: 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.linq4j.Linq4j.asEnumerable(new Double[] {
            0.1D});
          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() {
                      return (boolean) org.apache.calcite.runtime.SqlFunctions.toDouble(inputEnumerator.current());
                    }
        
                  };
              }
        
            };
        }
        
        
        public Class getElementType() {
          return boolean.class;
        }
        
        
        
            at org.apache.calcite.avatica.Helper.wrap(Helper.java:37)
            at org.apache.calcite.adapter.enumerable.EnumerableInterpretable.toBindable(EnumerableInterpretable.java:129)
            at org.apache.calcite.prepare.CalcitePrepareImpl$CalcitePreparingStmt.implement(CalcitePrepareImpl.java:1130)
            at org.apache.calcite.prepare.Prepare.prepareSql(Prepare.java:318)
            at org.apache.calcite.prepare.Prepare.prepareSql(Prepare.java:215)
            at org.apache.calcite.prepare.CalcitePrepareImpl.prepare2_(CalcitePrepareImpl.java:647)
            at org.apache.calcite.prepare.CalcitePrepareImpl.prepare_(CalcitePrepareImpl.java:513)
            at org.apache.calcite.prepare.CalcitePrepareImpl.prepareSql(CalcitePrepareImpl.java:483)
            at org.apache.calcite.jdbc.CalciteConnectionImpl.parseQuery(CalciteConnectionImpl.java:249)
            at org.apache.calcite.jdbc.CalciteMetaImpl.prepareAndExecute(CalciteMetaImpl.java:623)
            at org.apache.calcite.avatica.AvaticaConnection.prepareAndExecuteInternal(AvaticaConnection.java:675)
            at org.apache.calcite.avatica.AvaticaStatement.executeInternal(AvaticaStatement.java:156)
            ... 53 more
            Caused by: org.codehaus.commons.compiler.CompileException: Line 21, Column 31: Cannot cast "double" to "boolean"
                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.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:163)
                at org.apache.calcite.adapter.enumerable.EnumerableInterpretable.toBindable(EnumerableInterpretable.java:126)
{code}
The error occurred in the generated code:
{code:java}
// code placeholder
return (boolean) org.apache.calcite.runtime.SqlFunctions.toDouble(inputEnumerator.current());
{code}
Maybe we should fix it because I think these two test behaviors should be unified.



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