Uploaded image for project: 'Ignite'
  1. Ignite
  2. IGNITE-14612

Calcite. SELECT with CASE without boolean expression - fails.

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: sql
    • Labels:

      Description

      For example such expression - fails.

      SELECT CASE WHEN 1 THEN 13 ELSE 12 END;

      failed with:

      class org.apache.ignite.IgniteException: Error at: test_constant_comparisons.test:91. sql: SELECT CASE WHEN 1 THEN 13 ELSE 12 END;
      
      	at org.apache.ignite.internal.processors.query.calcite.logical.SqlScriptRunner$Query.execute(SqlScriptRunner.java:518)
      	at org.apache.ignite.internal.processors.query.calcite.logical.SqlScriptRunner.run(SqlScriptRunner.java:93)
      	at org.apache.ignite.internal.processors.query.calcite.logical.ScriptTestRunner$1.run(ScriptTestRunner.java:214)
      	at java.lang.Thread.run(Thread.java:748)
      Caused by: class org.apache.ignite.internal.processors.query.IgniteSQLException: Failed to plan query.
      	at org.apache.ignite.internal.processors.query.calcite.exec.ExecutionServiceImpl.prepareQuery(ExecutionServiceImpl.java:541)
      	at org.apache.ignite.internal.processors.query.calcite.prepare.QueryPlanCacheImpl.queryPlan(QueryPlanCacheImpl.java:84)
      	at org.apache.ignite.internal.processors.query.calcite.exec.ExecutionServiceImpl.executeQuery(ExecutionServiceImpl.java:398)
      	at org.apache.ignite.internal.processors.query.calcite.CalciteQueryProcessor.query(CalciteQueryProcessor.java:246)
      	at org.apache.ignite.internal.processors.query.calcite.logical.SqlScriptRunner.sql(SqlScriptRunner.java:111)
      	at org.apache.ignite.internal.processors.query.calcite.logical.SqlScriptRunner.access$600(SqlScriptRunner.java:51)
      	at org.apache.ignite.internal.processors.query.calcite.logical.SqlScriptRunner$Query.execute(SqlScriptRunner.java:513)
      	... 3 more
      Caused by: org.apache.calcite.runtime.CalciteContextException: From line 1, column 8 to line 1, column 38: Expected a boolean type
      	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
      	at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
      	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
      	at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
      	at org.apache.calcite.runtime.Resources$ExInstWithCause.ex(Resources.java:467)
      	at org.apache.calcite.sql.SqlUtil.newContextException(SqlUtil.java:883)
      

      and this work perfectly well:

      SELECT CASE WHEN 1=1 THEN 13 ELSE 12 END;

      a little reserch shows that calcite also fails in non boolean expression, root cause in
      SqlCaseOperator#checkOperandTypes and further check :

      if (!SqlTypeUtil.inBooleanFamily(type)

      if we change this place, appropriate test

        @Test void testCaseWhen2() {
          checkPlanEquals("SELECT CASE WHEN 1 THEN 13 ELSE 12 END");
        }

      will work fine in calcite but will fail in ignite with janino error:

      class org.apache.ignite.IgniteException: Line 3, Column 7: Not a boolean expression
      
      	at org.apache.ignite.internal.processors.query.calcite.util.Commons.compile(Commons.java:299)
      	at org.apache.ignite.internal.processors.query.calcite.exec.exp.ExpressionFactoryImpl.compile(ExpressionFactoryImpl.java:290)
      	at org.apache.ignite.internal.processors.query.calcite.exec.exp.ExpressionFactoryImpl.lambda$scalar$4(ExpressionFactoryImpl.java:241)
      	at java.util.concurrent.ConcurrentMap.computeIfAbsent(ConcurrentMap.java:324)
      	at org.apache.ignite.internal.processors.query.calcite.exec.exp.ExpressionFactoryImpl.scalar(ExpressionFactoryImpl.java:241)
      	at org.apache.ignite.internal.processors.query.calcite.exec.exp.ExpressionFactoryImpl.project(ExpressionFactoryImpl.java:198)
      	at org.apache.ignite.internal.processors.query.calcite.exec.LogicalRelImplementor.visit(LogicalRelImplementor.java:195)
      	at org.apache.ignite.internal.processors.query.calcite.exec.LogicalRelImplementor.visit(LogicalRelImplementor.java:102)
      	at org.apache.ignite.internal.processors.query.calcite.rel.IgniteProject.accept(IgniteProject.java:89)
      	at org.apache.ignite.internal.processors.query.calcite.exec.LogicalRelImplementor.visit(LogicalRelImplementor.java:615)
      	at org.apache.ignite.internal.processors.query.calcite.exec.LogicalRelImplementor.go(LogicalRelImplementor.java:630)
      	at org.apache.ignite.internal.processors.query.calcite.exec.ExecutionServiceImpl.executeQuery(ExecutionServiceImpl.java:752)
      	at org.apache.ignite.internal.processors.query.calcite.exec.ExecutionServiceImpl.executePlan(ExecutionServiceImpl.java:692)
      	at org.apache.ignite.internal.processors.query.calcite.exec.ExecutionServiceImpl.executePlans(ExecutionServiceImpl.java:418)
      	at org.apache.ignite.internal.processors.query.calcite.exec.ExecutionServiceImpl.executeQuery(ExecutionServiceImpl.java:400)
      	at org.apache.ignite.internal.processors.query.calcite.CalciteQueryProcessor.query(CalciteQueryProcessor.java:246)
      	at org.apache.ignite.internal.processors.query.calcite.logical.SqlScriptRunner.sql(SqlScriptRunner.java:111)
      	at org.apache.ignite.internal.processors.query.calcite.logical.SqlScriptRunner.access$600(SqlScriptRunner.java:51)
      	at org.apache.ignite.internal.processors.query.calcite.logical.SqlScriptRunner$Query.execute(SqlScriptRunner.java:513)
      	at org.apache.ignite.internal.processors.query.calcite.logical.SqlScriptRunner.run(SqlScriptRunner.java:93)
      	at org.apache.ignite.internal.processors.query.calcite.logical.ScriptTestRunner$1.run(ScriptTestRunner.java:214)
      	at java.lang.Thread.run(Thread.java:748)
      Caused by: org.codehaus.commons.compiler.CompileException: Line 3, Column 7: 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)
      	at org.codehaus.janino.UnitCompiler$14.visitIntegerLiteral(UnitCompiler.java:3965)
      	at org.codehaus.janino.UnitCompiler$14.visitIntegerLiteral(UnitCompiler.java:3935)
      	at org.codehaus.janino.Java$IntegerLiteral.accept(Java.java:5453)
      	at org.codehaus.janino.UnitCompiler.compileBoolean(UnitCompiler.java:3935)
      	at org.codehaus.janino.UnitCompiler.compile2(UnitCompiler.java:2464)
      	at org.codehaus.janino.UnitCompiler.access$1900(UnitCompiler.java:215)
      	at org.codehaus.janino.UnitCompiler$6.visitIfStatement(UnitCompiler.java:1495)
      	at org.codehaus.janino.UnitCompiler$6.visitIfStatement(UnitCompiler.java:1487)
      	at org.codehaus.janino.Java$IfStatement.accept(Java.java:2950)
      	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.ignite.internal.processors.query.calcite.util.Commons.compile(Commons.java:297)
      	... 21 more
      

      If we need such a syntax in future will dig it here.

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                zstan Stanilovsky Evgeny
                Reporter:
                zstan Stanilovsky Evgeny
              • Votes:
                0 Vote for this issue
                Watchers:
                3 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:

                  Time Tracking

                  Estimated:
                  Original Estimate - Not Specified
                  Not Specified
                  Remaining:
                  Remaining Estimate - 0h
                  0h
                  Logged:
                  Time Spent - 0.5h
                  0.5h