You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@calcite.apache.org by "jin xing (Jira)" <ji...@apache.org> on 2019/09/12 09:56:00 UTC
[jira] [Comment Edited] (CALCITE-3338) Error with executeBatch and
preparedStatement.
[ https://issues.apache.org/jira/browse/CALCITE-3338?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16928416#comment-16928416 ]
jin xing edited comment on CALCITE-3338 at 9/12/19 9:55 AM:
------------------------------------------------------------
CodeGen as below:
{code:java}
// code placeholder
---------------------
{
final org.apache.calcite.linq4j.Enumerable _inputEnumerable = org.apache.calcite.linq4j.Linq4j.asEnumerable(new Integer[] {
0});
final org.apache.calcite.linq4j.AbstractEnumerable child = new org.apache.calcite.linq4j.AbstractEnumerable(){
public org.apache.calcite.linq4j.Enumerator<Object[]> enumerator() {
return new org.apache.calcite.linq4j.Enumerator<Object[]>(){
public final org.apache.calcite.linq4j.Enumerator<int> inputEnumerator = _inputEnumerable.enumerator();
public void reset() {
inputEnumerator.reset();
} public boolean moveNext() {
return inputEnumerator.moveNext();
} public void close() {
inputEnumerator.close();
} public Object current() {
return new Object[] {
root.get("?0"),
root.get("?1"),
root.get("?2"),
root.get("?3"),
root.get("?4")};
} };
} };
final java.util.Collection collection = ((org.apache.calcite.schema.ModifiableTable) root.getRootSchema().getSubSchema("foo").getTable("bar")).getModifiableCollection();
final int _count = collection.size();
child.select(new org.apache.calcite.linq4j.function.Function1() {
public org.apache.calcite.test.JdbcTest.Employee apply(Object[] o) {
return new org.apache.calcite.test.JdbcTest.Employee(
org.apache.calcite.runtime.SqlFunctions.toInt(o[0]),
org.apache.calcite.runtime.SqlFunctions.toInt(o[1]),
o[2] == null ? (String) null : o[2].toString(),
org.apache.calcite.runtime.SqlFunctions.toFloat(o[3]),
(Integer) o[4]);
}
public Object apply(Object o) {
return apply(
(Object[]) o);
}
}
).into(collection);
final int _updatedCount = collection.size();
return org.apache.calcite.linq4j.Linq4j.singletonEnumerable((long) (_updatedCount >= _count ? _updatedCount - _count : _count - _updatedCount));
}
{code}
When parameter values failed to passed in, *org.apache.calcite.runtime.SqlFunctions.toInt(o[0]),* *org.apache.calcite.runtime.SqlFunctions.toInt(o[1])* , etc fails
was (Author: jinxing6042@126.com):
CodeGen as below:
{code:java}
// code placeholder
---------------------
{
final org.apache.calcite.linq4j.Enumerable _inputEnumerable = org.apache.calcite.linq4j.Linq4j.asEnumerable(new Integer[] {
0});
final org.apache.calcite.linq4j.AbstractEnumerable child = new org.apache.calcite.linq4j.AbstractEnumerable(){
public org.apache.calcite.linq4j.Enumerator<Object[]> enumerator() {
return new org.apache.calcite.linq4j.Enumerator<Object[]>(){
public final org.apache.calcite.linq4j.Enumerator<int> inputEnumerator = _inputEnumerable.enumerator();
public void reset() {
inputEnumerator.reset();
} public boolean moveNext() {
return inputEnumerator.moveNext();
} public void close() {
inputEnumerator.close();
} public Object current() {
return new Object[] {
root.get("?0"),
root.get("?1"),
root.get("?2"),
root.get("?3"),
root.get("?4")};
} };
} };
final java.util.Collection collection = ((org.apache.calcite.schema.ModifiableTable) root.getRootSchema().getSubSchema("foo").getTable("bar")).getModifiableCollection();
final int _count = collection.size();
child.select(new org.apache.calcite.linq4j.function.Function1() {
public org.apache.calcite.test.JdbcTest.Employee apply(Object[] o) {
return new org.apache.calcite.test.JdbcTest.Employee(
org.apache.calcite.runtime.SqlFunctions.toInt(o[0]),
org.apache.calcite.runtime.SqlFunctions.toInt(o[1]),
o[2] == null ? (String) null : o[2].toString(),
org.apache.calcite.runtime.SqlFunctions.toFloat(o[3]),
(Integer) o[4]);
}
public Object apply(Object o) {
return apply(
(Object[]) o);
}
}
).into(collection);
final int _updatedCount = collection.size();
return org.apache.calcite.linq4j.Linq4j.singletonEnumerable((long) (_updatedCount >= _count ? _updatedCount - _count : _count - _updatedCount));
}
{code}
When parameter values failed to passed in, *org.apache.calcite.runtime.SqlFunctions.toInt(o[0]),* *org.apache.calcite.runtime.SqlFunctions.toInt(o[1])* fails
> 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: 10m
> 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.2#803003)