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

NPE Array Type serialToJdbc in TypedValue when executeBatch

    XMLWordPrintableJSON

    Details

      Description

      I am using phoenix QueryServer upsert data in batch,the code as follows:

      @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();
              } 
      }
      

      When encounter Array type, I get an error NPE:

      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)
      

        Attachments

        1. Avatica-2939-master.patch
          0.8 kB
          shining
        2. CALCITE-2939-master-1.patch
          3 kB
          shining

          Issue Links

            Activity

              People

              • Assignee:
                danny0405 Danny Chan
                Reporter:
                shining shining
              • Votes:
                0 Vote for this issue
                Watchers:
                3 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 - 1h
                  1h