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

Error with executeBatch and preparedStatement.

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Open
    • Major
    • Resolution: Unresolved
    • 1.20.0
    • None
    • core
    • apache calcite 1.20

      java version "1.8.0_191"

      Java(TM) SE Runtime Environment (build 1.8.0_191-b12)

      Linux 4.15.0-60-generic #67-Ubuntu

    Description

      I did a test similar to org.apache.calcite.jdbc.CalciteRemoteDriverTest#testInsertBatch but in this case using preparedStatement instead of statement:

      
      @Test public void testInsertBatchWithPreparedStatement() throws Exception {
        final Connection connection = DriverManager.getConnection(
            "jdbc:avatica:remote:factory="
                + LocalServiceModifiableFactory.class.getName());
        assertThat(connection.getMetaData().supportsBatchUpdates(), is(true));
        assertThat(connection.isClosed(), is(false));
      
        PreparedStatement pst = connection.prepareStatement("insert into \"foo\".\"bar\" values (?,?,?,?,?)");
        pst.setInt(1,1);
        pst.setInt(2,1);
        pst.setString(3,"second");
        pst.setInt(4,1);
        pst.setInt(5,1);
        pst.addBatch();
        pst.addBatch();
      
        int[] updateCounts = pst.executeBatch();
        assertThat(updateCounts.length, is(2));
        assertThat(updateCounts[0], is(1));
        assertThat(updateCounts[1], is(1));
        ResultSet resultSet = pst.getResultSet();
        assertThat(resultSet, nullValue());
      
        // Now empty batch
        pst.clearBatch();
        updateCounts = pst.executeBatch();
        assertThat(updateCounts.length, is(0));
        resultSet = pst.getResultSet();
        assertThat(resultSet, nullValue());
      
        connection.close();
      }
      

      And I got weird exceptions:

      java.sql.SQLException 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.AvaticaConnection.executeBatchUpdateInternal(AvaticaConnection.java:595) at org.apache.calcite.avatica.AvaticaPreparedStatement.executeLargeBatch(AvaticaPreparedStatement.java:266) at org.apache.calcite.avatica.AvaticaPreparedStatement.executeBatch(AvaticaPreparedStatement.java:259) at org.apache.calcite.jdbc.CalciteRemoteDriverTest.testInsertBatchWithPreparedStatement(CalciteRemoteDriverTest.java:876) 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.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.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26) at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27) 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.NullPointerException at org.apache.calcite.runtime.SqlFunctions.cannotConvert(SqlFunctions.java:1534) at org.apache.calcite.runtime.SqlFunctions.toInt(SqlFunctions.java:1646) at Baz$2.apply(Unknown Source) at Baz$2.apply(Unknown Source) at org.apache.calcite.linq4j.EnumerableDefaults$10$1.current(EnumerableDefaults.java:1916) at org.apache.calcite.linq4j.EnumerableDefaults.into(EnumerableDefaults.java:2911) at org.apache.calcite.linq4j.DefaultEnumerable.into(DefaultEnumerable.java:340) at Baz.bind(Unknown Source) at org.apache.calcite.jdbc.CalcitePrepare$CalciteSignature.enumerable(CalcitePrepare.java:355) at org.apache.calcite.jdbc.CalciteConnectionImpl.enumerable(CalciteConnectionImpl.java:314) at org.apache.calcite.jdbc.CalciteMetaImpl._createIterable(CalciteMetaImpl.java:506) at org.apache.calcite.jdbc.CalciteMetaImpl.execute(CalciteMetaImpl.java:631) at org.apache.calcite.jdbc.CalciteMetaImpl.executeBatch(CalciteMetaImpl.java:652) at org.apache.calcite.avatica.remote.LocalService.apply(LocalService.java:365) at org.apache.calcite.avatica.remote.RemoteMeta$20.call(RemoteMeta.java:430) at org.apache.calcite.avatica.remote.RemoteMeta$20.call(RemoteMeta.java:427) at org.apache.calcite.avatica.AvaticaConnection.invokeWithRetries(AvaticaConnection.java:793) at org.apache.calcite.avatica.remote.RemoteMeta.executeBatch(RemoteMeta.java:427) at org.apache.calcite.avatica.AvaticaConnection.executeBatchUpdateInternal(AvaticaConnection.java:593) ... 27 more

       

      Attachments

        Activity

          People

            Unassigned Unassigned
            jacobroldan Jacob Roldan
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:

              Time Tracking

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