<?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>question Re: Fill 'Null' With Previous Row Values in Hive in Archives of Support Questions (Read Only)</title>
    <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/Fill-Null-With-Previous-Row-Values-in-Hive/m-p/290154#M31776</link>
    <description>&lt;P&gt;Also LEAD() function can be used with COALESCE()&lt;/P&gt;&lt;P&gt;For example&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;coalesce(sepan, lead(sepan, 1) over (partition by sourcedata order by timestamps)) as sepan&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;That will replace NULL values in sepan column with next non null value. The timestamps column could be ordered in asc order depending on the value you wan to copy.&lt;/P&gt;</description>
    <pubDate>Thu, 20 Feb 2020 11:52:05 GMT</pubDate>
    <dc:creator>Gosia</dc:creator>
    <dc:date>2020-02-20T11:52:05Z</dc:date>
    <item>
      <title>Fill 'Null' With Previous Row Values in Hive</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/Fill-Null-With-Previous-Row-Values-in-Hive/m-p/136878#M31767</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I just wanted to know is there a way to fill up &lt;STRONG&gt;null &lt;/STRONG&gt;values with previous value/record in Hive?&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Example:&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;date                employee          salary&lt;/P&gt;&lt;P&gt;5/16/16           Dave                 25,000&lt;/P&gt;&lt;P&gt;5/17/16           Richard             10,000&lt;/P&gt;&lt;P&gt;5/18/16           &lt;STRONG&gt;NULL                 NULL&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;5/17/16 Howard 50,000&lt;/P&gt;&lt;P&gt;5/18/16 &lt;STRONG&gt;NULL NULL&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;INTO:&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;date                employee          salary&lt;/P&gt;&lt;P&gt;5/16/16           Dave                 25,000&lt;/P&gt;&lt;P&gt;5/17/16           Richard             10,000&lt;/P&gt;&lt;P&gt;5/18/16 &lt;STRONG&gt;Richard 10,000&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;5/17/16 Howard 50,000&lt;/P&gt;&lt;P&gt;5/18/16 &lt;STRONG&gt;Howard 50,000&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;Assuming there's thousand records with several &lt;STRONG&gt;null values. &lt;/STRONG&gt;Appreciate your help on this.&lt;/P&gt;&lt;P&gt;To understand further, attached is my primary objective.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="4991-1.png" style="width: 622px;"&gt;&lt;img src="https://community.cloudera.com/t5/image/serverpage/image-id/21996iD9F4135AA71A1A4C/image-size/medium?v=v2&amp;amp;px=400" role="button" title="4991-1.png" alt="4991-1.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Bruce&lt;/P&gt;</description>
      <pubDate>Mon, 19 Aug 2019 08:47:44 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/Fill-Null-With-Previous-Row-Values-in-Hive/m-p/136878#M31767</guid>
      <dc:creator>bruce_a_perez</dc:creator>
      <dc:date>2019-08-19T08:47:44Z</dc:date>
    </item>
    <item>
      <title>Re: Fill 'Null' With Previous Row Values in Hive</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/Fill-Null-With-Previous-Row-Values-in-Hive/m-p/136879#M31768</link>
      <description>&lt;P style="margin-left: 40px;"&gt; &lt;A rel="user" href="https://community.cloudera.com/users/3524/bruceaperez.html" nodeid="3524"&gt;@Bruce Perez&lt;/A&gt;&lt;/P&gt;&lt;P style="margin-left: 40px;"&gt;If your data is in ORC format this can be done by simple performing a update statement on your table. &lt;/P&gt;&lt;P style="margin-left: 40px;"&gt;&lt;/P&gt;&lt;P&gt;INSERT ... VALUES, UPDATE, and DELETE SQL statements are supported in Apache Hive 0.14 and later. The INSERT ... VALUES statement enable users to write data to Apache Hive from values provided in SQL statements. The UPDATE and DELETE statements enable users to modify and delete values already written to Hive. All three statements support auto-commit, which means that each statement is a separate transaction that is automatically committed after the SQL statement is executed.&lt;/P&gt;&lt;P&gt;More information available &lt;A href="https://docs.hortonworks.com/HDPDocuments/HDP2/HDP-2.3.0/bk_dataintegration/content/new-feature-insert-values-update-delete.html"&gt;here&lt;/A&gt;.&lt;/P&gt;</description>
      <pubDate>Tue, 14 Jun 2016 11:31:25 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/Fill-Null-With-Previous-Row-Values-in-Hive/m-p/136879#M31768</guid>
      <dc:creator>sunile_manjee</dc:creator>
      <dc:date>2016-06-14T11:31:25Z</dc:date>
    </item>
    <item>
      <title>Re: Fill 'Null' With Previous Row Values in Hive</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/Fill-Null-With-Previous-Row-Values-in-Hive/m-p/136880#M31769</link>
      <description>&lt;P&gt; if your table is not in orc format, then create another table just like the one you have today like this:&lt;/P&gt;&lt;UL&gt;
&lt;LI&gt;&lt;CODE&gt;CREATE TABLE ... STORED AS ORC&lt;/CODE&gt;&lt;/LI&gt;&lt;LI&gt;&lt;CODE&gt;ALTER TABLE ... [PARTITION partition_spec] SET FILEFORMAT ORC&lt;/CODE&gt;&lt;/LI&gt;&lt;LI&gt;&lt;CODE&gt;SET hive.default.fileformat=Orc&lt;/CODE&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;then insert into this table from your existing table.  you can use statement INSERT INTO TABLE tablename1&lt;/P&gt;</description>
      <pubDate>Tue, 14 Jun 2016 11:36:00 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/Fill-Null-With-Previous-Row-Values-in-Hive/m-p/136880#M31769</guid>
      <dc:creator>sunile_manjee</dc:creator>
      <dc:date>2016-06-14T11:36:00Z</dc:date>
    </item>
    <item>
      <title>Re: Fill 'Null' With Previous Row Values in Hive</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/Fill-Null-With-Previous-Row-Values-in-Hive/m-p/136881#M31770</link>
      <description>&lt;P&gt;Thanks &lt;A rel="user" href="https://community.cloudera.com/users/1486/smanjee.html" nodeid="1486"&gt;@Sunile Manjee&lt;/A&gt;. The point is i'm creating a table based from a joined table (&lt;STRONG&gt;combined_table&lt;/STRONG&gt;). Next, I need to fill up the &lt;STRONG&gt;null &lt;/STRONG&gt;values in the &lt;STRONG&gt;combined_table &lt;/STRONG&gt;since I queried &lt;STRONG&gt;full outer join.&lt;/STRONG&gt; With the &lt;STRONG&gt;combined_table, &lt;/STRONG&gt;I need to fill up now the &lt;STRONG&gt;null &lt;/STRONG&gt;values based from the previous row value through created the &lt;STRONG&gt;derived_table&lt;/STRONG&gt;. I'm &lt;STRONG&gt;not using orc format.&lt;/STRONG&gt; &lt;/P&gt;</description>
      <pubDate>Tue, 14 Jun 2016 12:02:24 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/Fill-Null-With-Previous-Row-Values-in-Hive/m-p/136881#M31770</guid>
      <dc:creator>bruce_a_perez</dc:creator>
      <dc:date>2016-06-14T12:02:24Z</dc:date>
    </item>
    <item>
      <title>Re: Fill 'Null' With Previous Row Values in Hive</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/Fill-Null-With-Previous-Row-Values-in-Hive/m-p/136882#M31771</link>
      <description>&lt;P&gt;  As a next step you will need to create a table with orc format, fill the table with your joined dat using insert into select ..., then update it using method i have described..&lt;/P&gt;</description>
      <pubDate>Tue, 14 Jun 2016 19:47:49 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/Fill-Null-With-Previous-Row-Values-in-Hive/m-p/136882#M31771</guid>
      <dc:creator>sunile_manjee</dc:creator>
      <dc:date>2016-06-14T19:47:49Z</dc:date>
    </item>
    <item>
      <title>Re: Fill 'Null' With Previous Row Values in Hive</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/Fill-Null-With-Previous-Row-Values-in-Hive/m-p/136883#M31772</link>
      <description>&lt;P&gt;&lt;A rel="user" href="https://community.cloudera.com/users/3524/bruceaperez.html" nodeid="3524"&gt;@Bruce Perez&lt;/A&gt;  Are you looking for the SQL that will help you achieve the "filling" that you want to do? &lt;/P&gt;&lt;P&gt;
	Looking at your simplified picture, I created two tables: dates and date_rate and populated them with your sample data.  The query you can use to do the appropriate joins and "fill down" the missing values should look roughly like this.  There may be other methods, but in this one, we create a new view of your date_rate data, by assuming the "end_date" is one less than the next date_rate record.  Then, we can join the dates table onto that using the range instead.&lt;/P&gt;
&lt;PRE&gt;SELECT
  d.*,
  dr.*
FROM
  dates d LEFT OUTER JOIN
  (
    SELECT
      r1.rate,
      r1.dt AS start_date,
      MIN(DATE_SUB(r2.dt, 1)) AS end_date
    FROM
      date_rate r1 LEFT OUTER JOIN
      date_rate r2 ON r1.dt &amp;lt; r2.dt
    GROUP BY
      r1.rate, r1.dt
    ) dr ON d.dt &amp;gt;= dr.start_date AND (d.dt &amp;lt;= dr.end_date OR dr.end_date IS NULL)
ORDER BY
  d.dt
&lt;/PRE&gt;</description>
      <pubDate>Wed, 15 Jun 2016 02:59:24 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/Fill-Null-With-Previous-Row-Values-in-Hive/m-p/136883#M31772</guid>
      <dc:creator>paul_boal</dc:creator>
      <dc:date>2016-06-15T02:59:24Z</dc:date>
    </item>
    <item>
      <title>Re: Fill 'Null' With Previous Row Values in Hive</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/Fill-Null-With-Previous-Row-Values-in-Hive/m-p/136884#M31773</link>
      <description>&lt;P style="margin-left: 40px;"&gt; &lt;A rel="user" href="https://community.cloudera.com/users/3524/bruceaperez.html" nodeid="3524"&gt;@Bruce Perez&lt;/A&gt;&lt;/P&gt;&lt;P style="margin-left: 40px;"&gt;how about using COALESCE?  &lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;Returns the first v that is not NULL, or NULL if all v's are NULL.&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&lt;CODE&gt;SELECT COALESCE(datefield1, datefield2, datefield3) as first_date_found
FROM
tblDates
WHERE
primary_key = 1&lt;/CODE&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 15 Jun 2016 04:22:35 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/Fill-Null-With-Previous-Row-Values-in-Hive/m-p/136884#M31773</guid>
      <dc:creator>sunile_manjee</dc:creator>
      <dc:date>2016-06-15T04:22:35Z</dc:date>
    </item>
    <item>
      <title>Re: Fill 'Null' With Previous Row Values in Hive</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/Fill-Null-With-Previous-Row-Values-in-Hive/m-p/136885#M31774</link>
      <description>&lt;P&gt;&lt;A rel="user" href="https://community.cloudera.com/users/1486/smanjee.html" nodeid="1486"&gt;@Sunile Manjee&lt;/A&gt;: Yeah, I tried also COALESCE. Anyway, Thanks, appreciate your help&lt;/P&gt;</description>
      <pubDate>Wed, 15 Jun 2016 10:38:25 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/Fill-Null-With-Previous-Row-Values-in-Hive/m-p/136885#M31774</guid>
      <dc:creator>bruce_a_perez</dc:creator>
      <dc:date>2016-06-15T10:38:25Z</dc:date>
    </item>
    <item>
      <title>Re: Fill 'Null' With Previous Row Values in Hive</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/Fill-Null-With-Previous-Row-Values-in-Hive/m-p/136886#M31775</link>
      <description>&lt;P&gt;&lt;A rel="user" href="https://community.cloudera.com/users/813/paulboal.html" nodeid="813"&gt;@Paul Boal&lt;/A&gt;: Thanks, this is the nearest solution to my problem, just need modification on this one.&lt;/P&gt;</description>
      <pubDate>Wed, 15 Jun 2016 10:39:48 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/Fill-Null-With-Previous-Row-Values-in-Hive/m-p/136886#M31775</guid>
      <dc:creator>bruce_a_perez</dc:creator>
      <dc:date>2016-06-15T10:39:48Z</dc:date>
    </item>
    <item>
      <title>Re: Fill 'Null' With Previous Row Values in Hive</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/Fill-Null-With-Previous-Row-Values-in-Hive/m-p/290154#M31776</link>
      <description>&lt;P&gt;Also LEAD() function can be used with COALESCE()&lt;/P&gt;&lt;P&gt;For example&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;coalesce(sepan, lead(sepan, 1) over (partition by sourcedata order by timestamps)) as sepan&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;That will replace NULL values in sepan column with next non null value. The timestamps column could be ordered in asc order depending on the value you wan to copy.&lt;/P&gt;</description>
      <pubDate>Thu, 20 Feb 2020 11:52:05 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/Fill-Null-With-Previous-Row-Values-in-Hive/m-p/290154#M31776</guid>
      <dc:creator>Gosia</dc:creator>
      <dc:date>2020-02-20T11:52:05Z</dc:date>
    </item>
  </channel>
</rss>

