[
https://issues.apache.org/jira/browse/CALCITE-3338?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17420220#comment-17420220
]
xzh_dz commented on CALCITE-3338:
---------------------------------
[~julianhyde]
Thanks for review, I have submitted a
[PR|https://github.com/apache/calcite/pull/2373]. Please help review.Sorry, I
don't have permission to update the subject/description of the JIRA case.
As [~jacobroldan] [[email protected]] said,the parameter values are not
passed into *CalciteConnectionImpl#enumerable*. Details in
`org.apache.calcite.jdbc.CalciteMetaImpl#_createIterable`.
I rerun the test and get the error message below.The details can be found
according to the exception stack.
{code:java}
// code placeholder
Caused by: org.apache.calcite.runtime.CalciteException: Cannot convert null to
intCaused by: org.apache.calcite.runtime.CalciteException: Cannot convert null
to int 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:506) at
org.apache.calcite.runtime.Resources$ExInst.ex(Resources.java:600) at
org.apache.calcite.runtime.SqlFunctions.cannotConvert(SqlFunctions.java:1863)
at org.apache.calcite.runtime.SqlFunctions.toInt(SqlFunctions.java:1976) at
Baz$2.apply(Unknown Source) at Baz$2.apply(Unknown Source) at
org.apache.calcite.linq4j.EnumerableDefaults$17$1.current(EnumerableDefaults.java:2817)
at
org.apache.calcite.linq4j.EnumerableDefaults.into(EnumerableDefaults.java:3812)
at org.apache.calcite.linq4j.DefaultEnumerable.into(DefaultEnumerable.java:372)
at Baz.bind(Unknown Source) at
org.apache.calcite.jdbc.CalcitePrepare$CalciteSignature.enumerable(CalcitePrepare.java:363)
at
org.apache.calcite.jdbc.CalciteConnectionImpl.enumerable(CalciteConnectionImpl.java:333)
at
org.apache.calcite.jdbc.CalciteMetaImpl._createIterable(CalciteMetaImpl.java:578)
at org.apache.calcite.jdbc.CalciteMetaImpl.execute(CalciteMetaImpl.java:706)
at
org.apache.calcite.jdbc.CalciteMetaImpl.executeBatch(CalciteMetaImpl.java:727)
at org.apache.calcite.avatica.remote.LocalService.apply(LocalService.java:371)
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)
... 61 more
{code}
> Error with executeBatch and preparedStatement.
> ----------------------------------------------
>
> Key: CALCITE-3338
> URL: https://issues.apache.org/jira/browse/CALCITE-3338
> Project: Calcite
> Issue Type: Bug
> Components: core
> Affects Versions: 1.20.0
> Environment: 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
> Reporter: Jacob Roldan
> Priority: Major
> Labels: pull-request-available, test
> Time Spent: 4h
> Remaining Estimate: 0h
>
> I did a test similar to
> org.apache.calcite.jdbc.CalciteRemoteDriverTest#testInsertBatch but in this
> case using preparedStatement instead of statement:
> {code:java}
> @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();
> }
> {code}
> And I got weird exceptions:
> {noformat}
> 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{noformat}
>
--
This message was sent by Atlassian Jira
(v8.3.4#803005)