[ 
https://issues.apache.org/jira/browse/CALCITE-1050?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15975335#comment-15975335
 ] 

Josh Elser commented on CALCITE-1050:
-------------------------------------

bq. I don't think TypedValue is wrong. Its job is to send values over the wire, 
right? Array values aren't serializable, because they contain a connection. So 
I think you should serialize the values in the array (or map or struct or 
multiset) in something close to their native values then wrap them in your 
implementation of Array at the other end.

Yes, I agree with you on the serial/local forms. I'm more trying to reconcile 
what the docs say the JDBC form is used for. Here's a snippet of code which I'm 
trying to use to reason about this:

{code}
  @Test public void testSetJavaArray() throws Exception {
    try (Connection conn = DriverManager.getConnection(url)) {
      Integer[] data = new Integer[] {1, 2, 3, 4, 5};
      final Array array = conn.createArrayOf("INTEGER", data);
      final TypedValue arrayTypedValue =
          TypedValue.ofJdbc(Rep.ARRAY, array, Unsafe.localCalendar());
      final String tableName = "SET_JAVA_ARRAY";
      try (Statement stmt = conn.createStatement()) {
        assertFalse(stmt.execute("DROP TABLE IF EXISTS "  + tableName));
        assertFalse(stmt.execute("CREATE TABLE " + tableName + "(pk integer not 
null primary key,"
            + " numbers integer array)"));
      }
      try (PreparedStatement pstmt = conn.prepareStatement("INSERT INTO " + 
tableName
          + " values(?,?)")) {
        pstmt.setInt(1, 1);
        pstmt.setArray(2, (Array) 
arrayTypedValue.toJdbc(Unsafe.localCalendar()));
        assertEquals(1, pstmt.executeUpdate());
      }
  }
{code}

Given the javadoc, I'd expect the above to work. For a TypedValue, I should get 
an Object which is suitable to be set as an Array on the PreparedStatement. 
However, the above throws a ClassCastException (trying to cast Object[] to 
Array).

> Avatica can't serialize java.sql.Array
> --------------------------------------
>
>                 Key: CALCITE-1050
>                 URL: https://issues.apache.org/jira/browse/CALCITE-1050
>             Project: Calcite
>          Issue Type: Improvement
>          Components: avatica
>    Affects Versions: 1.5.0
>            Reporter: Lukas Lalinsky
>            Assignee: Josh Elser
>             Fix For: avatica-1.10.0
>
>
> As far as I can see, there is no way to serialize arrays in the Avatica RPC.



--
This message was sent by Atlassian JIRA
(v6.3.15#6346)

Reply via email to