You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@calcite.apache.org by "shining (JIRA)" <ji...@apache.org> on 2019/03/21 06:21:00 UTC
[jira] [Commented] (CALCITE-2939) NPE Array Type serialToJdbc in
TypedValue when executeBatch
[ https://issues.apache.org/jira/browse/CALCITE-2939?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16797861#comment-16797861 ]
shining commented on CALCITE-2939:
----------------------------------
I view the code of protoToJdbc method in TypedValue.java:
{code:java}
public static Object protoToJdbc(Common.TypedValue protoValue, Calendar calendar) {
Object o = getSerialFromProto(Objects.requireNonNull(protoValue));
// Shortcircuit the null
if (null == o) {
return o;
}
return serialToJdbc(Rep.fromProto(protoValue.getType()), null, o, calendar);
}
{code}
serialToJdbc method get componentRep null, but lack of null value processing when array type, this cause the NPE.
> NPE Array Type serialToJdbc in TypedValue when executeBatch
> -----------------------------------------------------------
>
> Key: CALCITE-2939
> URL: https://issues.apache.org/jira/browse/CALCITE-2939
> Project: Calcite
> Issue Type: Bug
> Components: avatica
> Affects Versions: 1.12.0
> Reporter: shining
> Priority: Major
>
> I am using phoenix QueryServer upsert data in batch,the code as follows:
> {code:java}
> @Test
> public void preparedStatementArrayTest() throws Exception {
> final String tableName = "TEST";
> try (Connection conn = DriverManager.getConnection("jdbc:phoenix:thin:http://localhost:8765");
> Statement stmt = conn.createStatement()) {
> conn.setAutoCommit(false);
> assertFalse(stmt.execute("DROP TABLE IF EXISTS " + tableName));
> assertFalse(stmt.execute("CREATE TABLE " + tableName + " ("
> + "pk VARCHAR NOT NULL PRIMARY KEY, "
> + "histogram INTEGER[])")
> );
> conn.commit();
> int numRows = 10;
> int numEvenElements = 4;
> int numOddElements = 6;
> try (PreparedStatement pstmt = conn.prepareStatement("UPSERT INTO " + tableName + " values(?, ?)")) {
> for (int i = 0; i < numRows; i++) {
> pstmt.setString(1, Integer.toString(i));
> int arrayLength = i % 2 == 0 ? numEvenElements : numOddElements;
> Object[] arrayData = new Object[arrayLength];
> for (int arrayOffset = 0; arrayOffset < arrayLength; arrayOffset++) {
> arrayData[arrayOffset] = Integer.toString(getArrayValueForOffset(arrayOffset));
> }
> pstmt.setArray(2, conn.createArrayOf("VARCHAR", arrayData));
> pstmt.addBatch();
> pstmt.executeBatch();
> }
> conn.commit();
> }
> }
> {code}
> When encounter Array type, I get an error NPE:
> {code:java}
> java.lang.NullPointerException
> at org.apache.calcite.avatica.remote.TypedValue.serialToJdbc(TypedValue.java:362)
> at org.apache.calcite.avatica.remote.TypedValue.protoToJdbc(TypedValue.java:895)
> at org.apache.calcite.avatica.jdbc.JdbcMeta.executeBatchProtobuf(JdbcMeta.java:986)
> at org.apache.calcite.avatica.remote.LocalService.apply(LocalService.java:363)
> at org.apache.calcite.avatica.remote.Service$ExecuteBatchRequest.accept(Service.java:2990)
> at org.apache.calcite.avatica.remote.Service$ExecuteBatchRequest.accept(Service.java:2942)
> at org.apache.calcite.avatica.remote.AbstractHandler.apply(AbstractHandler.java:94)
> {code}
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)