<?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 Convert a delta table (flattened json format) to a nested java object in Warehousing &amp; Analytics</title>
    <link>https://community.databricks.com/t5/warehousing-analytics/convert-a-delta-table-flattened-json-format-to-a-nested-java/m-p/118572#M2053</link>
    <description>&lt;P&gt;I have a delta table with columns like below format. I am querying Databricks using databricks-jdbc 2.7.1 driver. I want to convert the result set to a nested java object.&lt;BR /&gt;Order_actualPickupAddress_residential -&amp;gt; string&lt;BR /&gt;Order_pickupRequestDetails -&amp;gt; array&amp;lt;struct&amp;lt;pickupRequestOccurenceNumber:string,payorContact:struct&amp;lt;personName:string,companyName:string,phoneNumber:string&amp;gt;,pickupAddress:struct&amp;lt;classification:string,streetLines:array&amp;lt;string&amp;gt;,city:string,stateOrProvinceCode:string,postalCode:string,countryCode:string,residential:string&amp;gt;,softwareId:string,softwareVersion:string,deviceType:string,serviceOfferingId:string,primaryOrderConfirmationIdDetails:array&amp;lt;struct&amp;lt;id:string,type:string&amp;gt;&amp;gt;,requestReceivedDateTime:string,pickupDetailsByDay:array&amp;lt;struct&amp;lt;expectedDate:string,performingOpCo:string,expectedDateTimeWindow:struct&amp;lt;startDateTime:string,endDateTime:string&amp;gt;,attemptEngagementWindow:struct&amp;lt;startDateTime:string,endDateTime:string&amp;gt;,attemptOutcome:string&amp;gt;&amp;gt;&amp;gt;&amp;gt;&lt;BR /&gt;&lt;BR /&gt;I have a java object "Order" which has an object "pickupRequestDetails" which internally have "payorContact" object. what is an easy way to map 100s of such nested fields?&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 08 May 2025 17:48:13 GMT</pubDate>
    <dc:creator>tbmadhav</dc:creator>
    <dc:date>2025-05-08T17:48:13Z</dc:date>
    <item>
      <title>Convert a delta table (flattened json format) to a nested java object</title>
      <link>https://community.databricks.com/t5/warehousing-analytics/convert-a-delta-table-flattened-json-format-to-a-nested-java/m-p/118572#M2053</link>
      <description>&lt;P&gt;I have a delta table with columns like below format. I am querying Databricks using databricks-jdbc 2.7.1 driver. I want to convert the result set to a nested java object.&lt;BR /&gt;Order_actualPickupAddress_residential -&amp;gt; string&lt;BR /&gt;Order_pickupRequestDetails -&amp;gt; array&amp;lt;struct&amp;lt;pickupRequestOccurenceNumber:string,payorContact:struct&amp;lt;personName:string,companyName:string,phoneNumber:string&amp;gt;,pickupAddress:struct&amp;lt;classification:string,streetLines:array&amp;lt;string&amp;gt;,city:string,stateOrProvinceCode:string,postalCode:string,countryCode:string,residential:string&amp;gt;,softwareId:string,softwareVersion:string,deviceType:string,serviceOfferingId:string,primaryOrderConfirmationIdDetails:array&amp;lt;struct&amp;lt;id:string,type:string&amp;gt;&amp;gt;,requestReceivedDateTime:string,pickupDetailsByDay:array&amp;lt;struct&amp;lt;expectedDate:string,performingOpCo:string,expectedDateTimeWindow:struct&amp;lt;startDateTime:string,endDateTime:string&amp;gt;,attemptEngagementWindow:struct&amp;lt;startDateTime:string,endDateTime:string&amp;gt;,attemptOutcome:string&amp;gt;&amp;gt;&amp;gt;&amp;gt;&lt;BR /&gt;&lt;BR /&gt;I have a java object "Order" which has an object "pickupRequestDetails" which internally have "payorContact" object. what is an easy way to map 100s of such nested fields?&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 08 May 2025 17:48:13 GMT</pubDate>
      <guid>https://community.databricks.com/t5/warehousing-analytics/convert-a-delta-table-flattened-json-format-to-a-nested-java/m-p/118572#M2053</guid>
      <dc:creator>tbmadhav</dc:creator>
      <dc:date>2025-05-08T17:48:13Z</dc:date>
    </item>
    <item>
      <title>Re: Convert a delta table (flattened json format) to a nested java object</title>
      <link>https://community.databricks.com/t5/warehousing-analytics/convert-a-delta-table-flattened-json-format-to-a-nested-java/m-p/118687#M2057</link>
      <description>&lt;P&gt;Here are some suggestions/ideas to consider:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;DIV class="paragraph"&gt;To map hundreds of nested fields from a Databricks Delta table to complex Java objects like the &lt;CODE&gt;Order&lt;/CODE&gt; object described, consider the following approaches:&lt;/DIV&gt;
&lt;DIV class="paragraph"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV class="paragraph"&gt;1. &lt;STRONG&gt;Using Libraries for Object Mapping&lt;/STRONG&gt; Utilize libraries such as Jackson, Gson, or MapStruct in Java for structured mapping: - &lt;STRONG&gt;Jackson:&lt;/STRONG&gt; It is well-suited for mapping JSON-like structures to complex nested objects. Read the JDBC ResultSet into a JSON object and use &lt;CODE&gt;ObjectMapper&lt;/CODE&gt; to map it directly to your desired Java class structure. - Parse the result set: &lt;CODE&gt;java
    ObjectMapper objectMapper = new ObjectMapper();
    Order order = objectMapper.readValue(resultSetJson, Order.class);
    &lt;/CODE&gt; - Configure annotations on your Java classes, e.g., &lt;CODE&gt;@JsonProperty&lt;/CODE&gt; for specific mappings.&lt;/DIV&gt;
&lt;DIV class="paragraph"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV class="paragraph"&gt;2. &lt;STRONG&gt;Custom Mapping Functions&lt;/STRONG&gt; Write custom converter methods that traverse nested structures in the ResultSet and construct corresponding Java objects: - Iterate through the array and struct columns. - For nested fields, use recursive deserialization logic.&lt;/DIV&gt;
&lt;DIV class="paragraph"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV class="paragraph"&gt;3. &lt;STRONG&gt;Databricks-Specific Tools&lt;/STRONG&gt; If possible, transform your Delta table into a JSON-like structure via SQL before retrieving it using the JDBC driver. For example: &lt;CODE&gt;sql
SELECT to_json(struct(*)) AS json_data FROM delta_table
&lt;/CODE&gt; This returns each row as JSON, which makes mapping straightforward.&lt;/DIV&gt;
&lt;DIV class="paragraph"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV class="paragraph"&gt;4. &lt;STRONG&gt;Schema-Driven Approach&lt;/STRONG&gt; Switch to schema evolution techniques or utilize schema information to automate field mapping: - Delta Lake supports schema evolution to process changes in nested column structures efficiently. - Structure your Java objects to accommodate the schema evolution dynamically.&lt;/DIV&gt;
&lt;DIV class="paragraph"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV class="paragraph"&gt;Notes and Considerations - Ensure &lt;CODE&gt;databricks-jdbc&lt;/CODE&gt; compatibility to retrieve complex structures like arrays of structs. Libraries such as &lt;CODE&gt;Arrow&lt;/CODE&gt; (when enabled) simplify serialization but might require configurations like disabling &lt;CODE&gt;EnableArrow&lt;/CODE&gt; for better UTF-8 handling. - Nested structs (e.g., &lt;CODE&gt;struct&amp;lt;pickupRequestOccurenceNumber: string, ...&amp;gt;&lt;/CODE&gt;) must align with the Java class definition.&lt;/DIV&gt;
&lt;DIV class="paragraph"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV class="paragraph"&gt;Hope this helps, Lou.&lt;/DIV&gt;</description>
      <pubDate>Fri, 09 May 2025 13:57:24 GMT</pubDate>
      <guid>https://community.databricks.com/t5/warehousing-analytics/convert-a-delta-table-flattened-json-format-to-a-nested-java/m-p/118687#M2057</guid>
      <dc:creator>Louis_Frolio</dc:creator>
      <dc:date>2025-05-09T13:57:24Z</dc:date>
    </item>
  </channel>
</rss>

