<?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: lateral view explode in databricks  - need help in Data Engineering</title>
    <link>https://community.databricks.com/t5/data-engineering/lateral-view-explode-in-databricks-need-help/m-p/82916#M36774</link>
    <description>&lt;P&gt;Hi AzureSnowflake,&lt;/P&gt;&lt;P&gt;I see you're migrating from Snowflake to Databricks and running into some issues with the LATERAL FLATTEN function in Snowflake. Specifically, you're finding that the LATERAL VIEW EXPLODE in Databricks isn't providing the full output, particularly the indices, that you need to join related data from multiple array columns.&lt;/P&gt;&lt;P&gt;To work around this in Databricks, you can manually generate indices for each element in the arrays using functions like &lt;STRONG&gt;posexplode&lt;/STRONG&gt;, which provides both the index and value.&lt;/P&gt;&lt;P&gt;Please find the example below&lt;/P&gt;&lt;P&gt;SELECT&lt;BR /&gt;t.*,&lt;BR /&gt;p1.pos AS index,&lt;BR /&gt;p1.col1 AS value1,&lt;BR /&gt;p2.col2 AS value2&lt;BR /&gt;FROM&lt;BR /&gt;my_table t&lt;BR /&gt;LATERAL VIEW POSEXPLODE(t.col1) p1 AS index, col1&lt;BR /&gt;LATERAL VIEW POSEXPLODE(t.col2) p2 AS index, col2&lt;BR /&gt;WHERE&lt;BR /&gt;p1.index = p2.index&lt;/P&gt;&lt;P&gt;Just a thought, give a try and do let me know if it works!&lt;/P&gt;&lt;P&gt;Have a good day.&lt;/P&gt;</description>
    <pubDate>Wed, 14 Aug 2024 03:48:47 GMT</pubDate>
    <dc:creator>Brahmareddy</dc:creator>
    <dc:date>2024-08-14T03:48:47Z</dc:date>
    <item>
      <title>lateral view explode in databricks  - need help</title>
      <link>https://community.databricks.com/t5/data-engineering/lateral-view-explode-in-databricks-need-help/m-p/82825#M36741</link>
      <description>&lt;DIV&gt;We are working on snowflake to databricks migration and we encountered the lateral flatten function of snowflake which we tried to convert to lateral view explode in databricks- but its output is a subset of lateral flatten&lt;/DIV&gt;&lt;DIV&gt;-----------------------&lt;/DIV&gt;&lt;DIV&gt;&lt;A href="https://docs.snowflake.com/en/sql-reference/functions/flatten" target="_blank" rel="noopener"&gt;https://docs.snowflake.com/en/sql-reference/functions/flatten&lt;/A&gt;&lt;/DIV&gt;&lt;DIV&gt;The output of this flatten contains a result containing 6 elements as shown on this page with&amp;nbsp; (index,value) being major in some of the queries&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;In case of tables with multiple array columns - these index values are used to combine data stored in 2 different array columns by performing joins&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;e.g.&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;col1 &amp;lt;1,2,3&amp;gt;, col2 &amp;lt;abc,def,ghi&amp;gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;indices of 1 and abc, 2 and def, 3 and ghi are same and they are related data values stored in 2 different columns in a table&lt;/DIV&gt;&lt;DIV&gt;--------------------------------------&lt;/DIV&gt;&lt;DIV&gt;However,in Databricks - its equivalent is LATERAL VIEW [OUTER] EXPLODE&amp;nbsp; - which just returns the exploded values and not their indices.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;this doesn't allow us to combine such data items as mentioned above&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;A href="https://docs.databricks.com/en/sql/language-manual/sql-ref-syntax-qry-select-lateral-view.html" target="_blank" rel="noopener"&gt;https://docs.databricks.com/en/sql/language-manual/sql-ref-syntax-qry-select-lateral-view.html&lt;/A&gt;&lt;/DIV&gt;&lt;DIV&gt;---------------------------&lt;/DIV&gt;&lt;DIV&gt;Any suggestions would be helpful&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;</description>
      <pubDate>Tue, 13 Aug 2024 05:33:30 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/lateral-view-explode-in-databricks-need-help/m-p/82825#M36741</guid>
      <dc:creator>koantek_user</dc:creator>
      <dc:date>2024-08-13T05:33:30Z</dc:date>
    </item>
    <item>
      <title>Re: lateral view explode in databricks  - need help</title>
      <link>https://community.databricks.com/t5/data-engineering/lateral-view-explode-in-databricks-need-help/m-p/82916#M36774</link>
      <description>&lt;P&gt;Hi AzureSnowflake,&lt;/P&gt;&lt;P&gt;I see you're migrating from Snowflake to Databricks and running into some issues with the LATERAL FLATTEN function in Snowflake. Specifically, you're finding that the LATERAL VIEW EXPLODE in Databricks isn't providing the full output, particularly the indices, that you need to join related data from multiple array columns.&lt;/P&gt;&lt;P&gt;To work around this in Databricks, you can manually generate indices for each element in the arrays using functions like &lt;STRONG&gt;posexplode&lt;/STRONG&gt;, which provides both the index and value.&lt;/P&gt;&lt;P&gt;Please find the example below&lt;/P&gt;&lt;P&gt;SELECT&lt;BR /&gt;t.*,&lt;BR /&gt;p1.pos AS index,&lt;BR /&gt;p1.col1 AS value1,&lt;BR /&gt;p2.col2 AS value2&lt;BR /&gt;FROM&lt;BR /&gt;my_table t&lt;BR /&gt;LATERAL VIEW POSEXPLODE(t.col1) p1 AS index, col1&lt;BR /&gt;LATERAL VIEW POSEXPLODE(t.col2) p2 AS index, col2&lt;BR /&gt;WHERE&lt;BR /&gt;p1.index = p2.index&lt;/P&gt;&lt;P&gt;Just a thought, give a try and do let me know if it works!&lt;/P&gt;&lt;P&gt;Have a good day.&lt;/P&gt;</description>
      <pubDate>Wed, 14 Aug 2024 03:48:47 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/lateral-view-explode-in-databricks-need-help/m-p/82916#M36774</guid>
      <dc:creator>Brahmareddy</dc:creator>
      <dc:date>2024-08-14T03:48:47Z</dc:date>
    </item>
    <item>
      <title>Re: lateral view explode in databricks  - need help</title>
      <link>https://community.databricks.com/t5/data-engineering/lateral-view-explode-in-databricks-need-help/m-p/82926#M36778</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.databricks.com/t5/user/viewprofilepage/user-id/109285"&gt;@koantek_user&lt;/a&gt;, Thanks for reaching out! Please review the response and let us know if it answers your question. Your feedback is valuable to us and the community.&lt;/P&gt;
&lt;P&gt;If the response resolves your issue, kindly mark it as the accepted solution. This will help close the thread and assist others with similar queries.&lt;/P&gt;
&lt;P&gt;We appreciate your participation and are here if you need further assistance!&lt;/P&gt;</description>
      <pubDate>Wed, 14 Aug 2024 07:59:13 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/lateral-view-explode-in-databricks-need-help/m-p/82926#M36778</guid>
      <dc:creator>Retired_mod</dc:creator>
      <dc:date>2024-08-14T07:59:13Z</dc:date>
    </item>
  </channel>
</rss>

