Uploaded image for project: 'Calcite'
  1. Calcite
  2. CALCITE-3494

Support decimal type aggregate in Interpreter

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • None
    • 1.22.0
    • None

    Description

      Using decimal type aggregate in Interpreter cause exception.

      Add this case in InterpreterTest to reproduce.

      @Test public void testDecimalType() throws Exception {
          final String sql = "select x, min(y), max(y), sum(y)\n"
              + "from (values ('a', 1.2), ('a', 2.3), ('a', 15)) as t(x, y)\n"
              + "group by x";
          sql(sql).returnsRows("[a, 1.2, 15.0, 18.5]");
        }
      

      The stack trace is like this

      java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
      
      	at org.apache.calcite.interpreter.AggregateNode$UdaAccumulator.send(AggregateNode.java:662)
      	at org.apache.calcite.interpreter.AggregateNode$AccumulatorList.send(AggregateNode.java:398)
      	at org.apache.calcite.interpreter.AggregateNode$Grouping.send(AggregateNode.java:366)
      	at org.apache.calcite.interpreter.AggregateNode.run(AggregateNode.java:96)
      	at org.apache.calcite.interpreter.Interpreter.start(Interpreter.java:130)
      	at org.apache.calcite.interpreter.Interpreter.enumerator(Interpreter.java:107)
      	at org.apache.calcite.linq4j.AbstractEnumerable.iterator(AbstractEnumerable.java:33)
      	at org.apache.calcite.test.InterpreterTest.assertRows(InterpreterTest.java:173)
      	at org.apache.calcite.test.InterpreterTest.access$100(InterpreterTest.java:51)
      	at org.apache.calcite.test.InterpreterTest$Sql.returnsRows(InterpreterTest.java:122)
      	at org.apache.calcite.test.InterpreterTest$Sql.returnsRows(InterpreterTest.java:105)
      	at org.apache.calcite.test.InterpreterTest.testDecimalType(InterpreterTest.java:441)
      	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
      	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      	at java.lang.reflect.Method.invoke(Method.java:498)
      	at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
      	at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
      	at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
      	at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
      	at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
      	at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
      	at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
      	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
      	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
      	at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
      	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
      	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
      	at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
      	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
      	at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
      	at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
      	at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
      	at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)
      	at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
      	at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
      Caused by: java.lang.reflect.InvocationTargetException
      	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
      	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      	at java.lang.reflect.Method.invoke(Method.java:498)
      	at org.apache.calcite.interpreter.AggregateNode$UdaAccumulator.send(AggregateNode.java:660)
      	... 35 more
      Caused by: java.lang.ClassCastException: java.math.BigDecimal cannot be cast to java.lang.Long
      	at org.apache.calcite.interpreter.AggregateNode$NumericComparison.add(AggregateNode.java:494)
      	... 40 more
      
      

      Attachments

        Issue Links

          Activity

            People

              yanlin-Lynn Wang Yanlin
              yanlin-Lynn Wang Yanlin
              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