<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: How to fetch nested data structures in Databricks using JDBC in Get Started Discussions</title>
    <link>https://community.databricks.com/t5/get-started-discussions/how-to-fetch-nested-data-structures-in-databricks-using-jdbc/m-p/109984#M4808</link>
    <description>&lt;P&gt;2.6.40 exposes the same behaviour.&lt;/P&gt;</description>
    <pubDate>Wed, 12 Feb 2025 13:14:03 GMT</pubDate>
    <dc:creator>lukaseder</dc:creator>
    <dc:date>2025-02-12T13:14:03Z</dc:date>
    <item>
      <title>How to fetch nested data structures in Databricks using JDBC</title>
      <link>https://community.databricks.com/t5/get-started-discussions/how-to-fetch-nested-data-structures-in-databricks-using-jdbc/m-p/109981#M4805</link>
      <description>&lt;P&gt;I've asked the question also here on &lt;A href="https://stackoverflow.com/q/79432459/521799" target="_self"&gt;stack overflow&lt;/A&gt;&lt;/P&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;When using nested data structures in Databricks (e.g. `ARRAY` or `ROW`) using JDBC, it appears that the results can be fetched as JSON `String` values, e.g.:&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;PRE&gt;try (Statement s = connection.createStatement();&lt;BR /&gt;&amp;nbsp; &amp;nbsp; ResultSet rs = s.executeQuery(&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; """&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; select array(1, 2), array('a', 'b'), array(true, false)&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; """&lt;BR /&gt;)) {&lt;BR /&gt;&amp;nbsp; &amp;nbsp; while (rs.next()) {&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; System.out.println(rs.getString(1));&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; System.out.println(rs.getObject(1).getClass());&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; System.out.println(rs.getString(2));&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; System.out.println(rs.getObject(2).getClass());&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; System.out.println(rs.getString(3));&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; System.out.println(rs.getObject(3).getClass());&lt;BR /&gt;&amp;nbsp; &amp;nbsp; }&lt;BR /&gt;}&lt;/PRE&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Produces valid JSON strings (at least, that's what they look like):&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;PRE&gt;[1,2]&lt;BR /&gt;class java.lang.String&lt;BR /&gt;["a","b"]&lt;BR /&gt;class java.lang.String&lt;BR /&gt;[true,false]&lt;BR /&gt;class java.lang.String&lt;/PRE&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Calling `ResultSet::getArray` isn't implemented:&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;PRE&gt;java.sql.SQLDataException: [Databricks][JDBC](10400) Invalid type for data - column: 3, type: Array.&lt;BR /&gt;&lt;SPAN&gt; at com.databricks.client.exceptions.ExceptionConverter.toSQLException(Unknown Source)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; at com.databricks.client.jdbc.common.SForwardResultSet.getArray(Unknown Source)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; at org.jooq.testscripts.JDBC.main(JDBC.java:44)&lt;/SPAN&gt;&lt;/PRE&gt;&lt;DIV&gt;This seems fine until the array contains `"` characters, e.g. this query `select array('"')` produces this invalid value:&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;PRE&gt;["""]&lt;/PRE&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Instead of:&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;PRE&gt;["\""]&lt;/PRE&gt;&lt;DIV&gt;Likewise, when reading `select array(date '2000-01-01')`, I'm getting:&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;PRE&gt;[2000-01-01]&lt;/PRE&gt;&lt;DIV&gt;Instead of e.g.:&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;PRE&gt;["2000-01-01"]&lt;/PRE&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Is this a known bug / limitation in the 2.7.1 JDBC driver version that I'm using? Is there a known workaround?&lt;/DIV&gt;</description>
      <pubDate>Wed, 12 Feb 2025 13:05:34 GMT</pubDate>
      <guid>https://community.databricks.com/t5/get-started-discussions/how-to-fetch-nested-data-structures-in-databricks-using-jdbc/m-p/109981#M4805</guid>
      <dc:creator>lukaseder</dc:creator>
      <dc:date>2025-02-12T13:05:34Z</dc:date>
    </item>
    <item>
      <title>Re: How to fetch nested data structures in Databricks using JDBC</title>
      <link>https://community.databricks.com/t5/get-started-discussions/how-to-fetch-nested-data-structures-in-databricks-using-jdbc/m-p/109983#M4807</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.databricks.com/t5/user/viewprofilepage/user-id/142653"&gt;@lukaseder&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;This looks to be a bug, but will get more details about it internally. The driver is relatively new.&lt;/P&gt;
&lt;P&gt;Have you tried with another version, for instance JDBC:&amp;nbsp;&lt;SPAN&gt;2.6.40&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 12 Feb 2025 13:11:22 GMT</pubDate>
      <guid>https://community.databricks.com/t5/get-started-discussions/how-to-fetch-nested-data-structures-in-databricks-using-jdbc/m-p/109983#M4807</guid>
      <dc:creator>Alberto_Umana</dc:creator>
      <dc:date>2025-02-12T13:11:22Z</dc:date>
    </item>
    <item>
      <title>Re: How to fetch nested data structures in Databricks using JDBC</title>
      <link>https://community.databricks.com/t5/get-started-discussions/how-to-fetch-nested-data-structures-in-databricks-using-jdbc/m-p/109984#M4808</link>
      <description>&lt;P&gt;2.6.40 exposes the same behaviour.&lt;/P&gt;</description>
      <pubDate>Wed, 12 Feb 2025 13:14:03 GMT</pubDate>
      <guid>https://community.databricks.com/t5/get-started-discussions/how-to-fetch-nested-data-structures-in-databricks-using-jdbc/m-p/109984#M4808</guid>
      <dc:creator>lukaseder</dc:creator>
      <dc:date>2025-02-12T13:14:03Z</dc:date>
    </item>
  </channel>
</rss>

