<?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: Unpivoting data in live tables in Get Started Discussions</title>
    <link>https://community.databricks.com/t5/get-started-discussions/unpivoting-data-in-live-tables/m-p/55268#M6264</link>
    <description>&lt;P&gt;Thanks Kaniz.&amp;nbsp; I had chatGPT write me a python script to generate the UNION, but I will keep this function in mind if I revisit it.&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 14 Dec 2023 17:36:49 GMT</pubDate>
    <dc:creator>SamGreene</dc:creator>
    <dc:date>2023-12-14T17:36:49Z</dc:date>
    <item>
      <title>Unpivoting data in live tables</title>
      <link>https://community.databricks.com/t5/get-started-discussions/unpivoting-data-in-live-tables/m-p/55219#M6262</link>
      <description>&lt;P&gt;I am loading data from CSV into live tables.&amp;nbsp; I have a live delta table with data like this:&lt;/P&gt;&lt;P&gt;WaterMeterID, ReadingDateTime1, ReadingValue1, ReadingDateTime2, ReadingValue2&lt;/P&gt;&lt;P&gt;It needs to be unpivoted into this:&lt;/P&gt;&lt;P&gt;WaterMeterID, ReadingDateTime1, ReadingValue1&lt;/P&gt;&lt;P&gt;WaterMeterID, ReadingDateTime2, ReadingValue2&lt;/P&gt;&lt;P&gt;There are typically 24 sets of the pivoted pairs - ReadingDateTime1 - 24.&amp;nbsp; I could write a SQL statement with 24 unions to unpivot the data.&amp;nbsp; It seems the UNPIVOT clause can't handle this.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Can you recommend how this could be done and work with live tables to do full or incremental refreshes of the unpivoted data?&amp;nbsp; We could write Spark code to do it, but we'd need to unpivot all the data each time we process the upstream data - or keep track of what data we have loaded by using a watermark table and process only the added data.&amp;nbsp; But then, if a full refresh is performed via pipeline, we'd also need to reset the watermark table, which complicates the maintenance.&amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/P&gt;&lt;P&gt;Once we have all the water meters running, we'll have about 300K pivoted lines per day to process.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 14 Dec 2023 00:36:28 GMT</pubDate>
      <guid>https://community.databricks.com/t5/get-started-discussions/unpivoting-data-in-live-tables/m-p/55219#M6262</guid>
      <dc:creator>SamGreene</dc:creator>
      <dc:date>2023-12-14T00:36:28Z</dc:date>
    </item>
    <item>
      <title>Re: Unpivoting data in live tables</title>
      <link>https://community.databricks.com/t5/get-started-discussions/unpivoting-data-in-live-tables/m-p/55268#M6264</link>
      <description>&lt;P&gt;Thanks Kaniz.&amp;nbsp; I had chatGPT write me a python script to generate the UNION, but I will keep this function in mind if I revisit it.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 14 Dec 2023 17:36:49 GMT</pubDate>
      <guid>https://community.databricks.com/t5/get-started-discussions/unpivoting-data-in-live-tables/m-p/55268#M6264</guid>
      <dc:creator>SamGreene</dc:creator>
      <dc:date>2023-12-14T17:36:49Z</dc:date>
    </item>
  </channel>
</rss>

