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

NullPointerException when deserialize UDAF aggregate call from json string

    XMLWordPrintableJSON

    Details

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

      Description

      When serialize a relation algebra which contains udaf aggregate call, it works well and get the json string.
      But when deserialize from the json string, got NullPointerException as below

      java.lang.RuntimeException: java.lang.NullPointerException
      
      	at org.apache.calcite.tools.Frameworks.withPrepare(Frameworks.java:182)
      	at org.apache.calcite.tools.Frameworks.withPlanner(Frameworks.java:126)
      	at org.apache.calcite.tools.Frameworks.withPlanner(Frameworks.java:144)
      	at org.apache.calcite.plan.RelWriterTest.deserializeAndDumpToTextFormat(RelWriterTest.java:828)
      	at org.apache.calcite.plan.RelWriterTest.testUDAF(RelWriterTest.java:921)
      	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.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.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 java.util.ArrayList.forEach(ArrayList.java:1257)
      	at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.invokeAll(SameThreadHierarchicalTestExecutorService.java:38)
      	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 java.util.ArrayList.forEach(ArrayList.java:1257)
      	at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.invokeAll(SameThreadHierarchicalTestExecutorService.java:38)
      	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.SameThreadHierarchicalTestExecutorService.submit(SameThreadHierarchicalTestExecutorService.java:32)
      	at org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor.execute(HierarchicalTestExecutor.java:57)
      	at org.junit.platform.engine.support.hierarchical.HierarchicalTestEngine.execute(HierarchicalTestEngine.java:51)
      	at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:248)
      	at org.junit.platform.launcher.core.DefaultLauncher.lambda$execute$5(DefaultLauncher.java:211)
      	at org.junit.platform.launcher.core.DefaultLauncher.withInterceptedStreams(DefaultLauncher.java:226)
      	at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:199)
      	at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:132)
      	at com.intellij.junit5.JUnit5IdeaTestRunner.startRunnerWithArgs(JUnit5IdeaTestRunner.java:69)
      	at com.intellij.rt.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:33)
      	at com.intellij.rt.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:230)
      	at com.intellij.rt.junit.JUnitStarter.main(JUnitStarter.java:58)
      Caused by: java.lang.NullPointerException
      	at java.util.Objects.requireNonNull(Objects.java:203)
      	at org.apache.calcite.rel.core.AggregateCall.<init>(AggregateCall.java:98)
      	at org.apache.calcite.rel.core.AggregateCall.create(AggregateCall.java:198)
      	at org.apache.calcite.rel.externalize.RelJsonReader.toAggCall(RelJsonReader.java:286)
      	at org.apache.calcite.rel.externalize.RelJsonReader.access$500(RelJsonReader.java:59)
      	at org.apache.calcite.rel.externalize.RelJsonReader$2.getAggregateCalls(RelJsonReader.java:172)
      	at org.apache.calcite.rel.core.Aggregate.<init>(Aggregate.java:220)
      	at org.apache.calcite.rel.logical.LogicalAggregate.<init>(LogicalAggregate.java:105)
      	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.rel.externalize.RelJsonReader.readRel(RelJsonReader.java:261)
      	at org.apache.calcite.rel.externalize.RelJsonReader.readRels(RelJsonReader.java:91)
      	at org.apache.calcite.rel.externalize.RelJsonReader.read(RelJsonReader.java:85)
      	at org.apache.calcite.plan.RelWriterTest.lambda$deserializeAndDumpToTextFormat$6(RelWriterTest.java:833)
      	at org.apache.calcite.tools.Frameworks.lambda$withPlanner$0(Frameworks.java:131)
      	at org.apache.calcite.prepare.CalcitePrepareImpl.perform(CalcitePrepareImpl.java:914)
      	at org.apache.calcite.tools.Frameworks.withPrepare(Frameworks.java:180)
      	... 67 more
      

      Add this test case in RelWriterTest to reproduce

      @Test void testUDAF(){
          final FrameworkConfig config = RelBuilderTest.config().build();
          final RelBuilder builder = RelBuilder.create(config);
          final RelNode rel = builder
              .scan("EMP")
              .project(builder.field("ENAME"), builder.field("DEPTNO"))
              .aggregate(
                  builder.groupKey("ENAME"),
                  builder.aggregateCall(MyAggFunc.INSTANCE, builder.field("DEPTNO")))
              .build();
          String relJson = RelOptUtil.dumpPlan("", rel,
              SqlExplainFormat.JSON, SqlExplainLevel.EXPPLAN_ATTRIBUTES);
          final String s = deserializeAndDumpToTextFormat(getSchema(rel), relJson);
          final String expected =
              "LogicalAggregate(group=[{0}], agg#0=[myAggFunc($1)])\n" +
                  "  LogicalProject(ENAME=[$1], DEPTNO=[$7])\n" +
                  "    LogicalTableScan(table=[[scott, EMP]])\n";
          assertThat(s, isLinux(expected));
        }
      

      The definition of MyAggFunc is

      public static class MyAggFunc extends SqlAggFunction {
      
          protected MyAggFunc(String name, SqlIdentifier sqlIdentifier, SqlKind kind,
              SqlReturnTypeInference returnTypeInference,
              SqlOperandTypeInference operandTypeInference,
              SqlOperandTypeChecker operandTypeChecker,
              SqlFunctionCategory funcType, boolean requiresOrder, boolean requiresOver,
              Optionality requiresGroupOrder) {
            super(name, sqlIdentifier, kind, returnTypeInference,
                operandTypeInference, operandTypeChecker, funcType, requiresOrder,
                requiresOver, requiresGroupOrder);
          }
      
          public static MyAggFunc INSTANCE = new MyAggFunc(
              "myAggFunc",
              null,
              SqlKind.OTHER_FUNCTION,
              ReturnTypes.BIGINT,
              null,
              OperandTypes.ONE_OR_MORE,
              SqlFunctionCategory.USER_DEFINED_FUNCTION,
              false,
              false,
              Optionality.FORBIDDEN
          );
        }
      

        Attachments

          Activity

            People

            • Assignee:
              yanlin-Lynn Wang Yanlin
              Reporter:
              yanlin-Lynn Wang Yanlin
            • Votes:
              0 Vote for this issue
              Watchers:
              6 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 - 2h
                2h