<?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: Hive transpose concatenated data in columns to rows in Archives of Support Questions (Read Only)</title>
    <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/Hive-transpose-concatenated-data-in-columns-to-rows/m-p/181546#M61578</link>
    <description>&lt;P&gt;&lt;A rel="user" href="https://community.cloudera.com/users/18497/dhanya2kumar.html" nodeid="18497"&gt;@Dhanya Kumar Heballi Shivamurthy&lt;/A&gt;, please accept the answer to close the thread.&lt;/P&gt;</description>
    <pubDate>Thu, 25 May 2017 20:27:41 GMT</pubDate>
    <dc:creator>eberezitsky</dc:creator>
    <dc:date>2017-05-25T20:27:41Z</dc:date>
    <item>
      <title>Hive transpose concatenated data in columns to rows</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/Hive-transpose-concatenated-data-in-columns-to-rows/m-p/181543#M61575</link>
      <description>&lt;P&gt;I am new to hive and I need some help to transpose concatenated data in columns to rows. My hive table consists of subset of columns which contains concatenated values delimited by pipe or comma. I want to transpose it to rows using explode lateral view. &lt;/P&gt;&lt;P&gt;
Input table &lt;/P&gt;&lt;P&gt;column1,                            column2,                                          column3,                                          column4 &lt;/P&gt;&lt;P&gt;id1,                              Delta|Alpha|Beta,                            Source|Varied|Volume,                           AppData &lt;/P&gt;&lt;P&gt;Output table &lt;/P&gt;&lt;P&gt;column1,                           column2,                                          column3,                                          column4 &lt;/P&gt;&lt;P&gt;id1,                                    Delta,                                                Source,                                           AppData &lt;/P&gt;&lt;P&gt;id1,                                   Alpha,                                                Varied,                                             AppData &lt;/P&gt;&lt;P&gt;id1,                                   Beta,                                                  Volume,                                          AppData&lt;/P&gt;</description>
      <pubDate>Mon, 22 May 2017 20:10:09 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/Hive-transpose-concatenated-data-in-columns-to-rows/m-p/181543#M61575</guid>
      <dc:creator>dhanya2kumar</dc:creator>
      <dc:date>2017-05-22T20:10:09Z</dc:date>
    </item>
    <item>
      <title>Re: Hive transpose concatenated data in columns to rows</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/Hive-transpose-concatenated-data-in-columns-to-rows/m-p/181544#M61576</link>
      <description>&lt;P&gt;&lt;A rel="user" href="https://community.cloudera.com/users/18497/dhanya2kumar.html" nodeid="18497"&gt;@Dhanya Kumar Heballi Shivamurthy&lt;/A&gt;,&lt;/P&gt;&lt;P&gt;assuming you have both arrays with the same size (per record):&lt;/P&gt;&lt;PRE&gt;select 
  c1, 
  c21,
  c31,
  c4 
from (
    select 100 c1, split('Delta|Alpha|Beta','\\|') c2, split('Source|Varied|Volume','\\|') c3, 'AppData' c4
) foo
LATERAL VIEW posexplode(c2) n1  as c22, c21
LATERAL VIEW posexplode(c3) n2  as c32, c31
where c22=c32;
&lt;/PRE&gt;&lt;P&gt;If array lengths can be different, then you need to add more conditions:&lt;/P&gt;&lt;PRE&gt;select c1, c222 c2, c333 c3, c4 
from (
select 
  c1, 
  c22, c32, -- keep indices
  case when c32 &amp;lt; size(c2) then c21 else null end c222,
  case when c22 &amp;lt; size(c3) then c31 else null end c333,
  c4 
from (
    select 100 c1, split('Delta|Alpha|Beta','\\|') c2, split('Source|Varied|Volume|Owner','\\|') c3, 'AppData' c4
) foo
LATERAL VIEW posexplode(c2) n1  as c22, c21
LATERAL VIEW posexplode(c3) n2  as c32, c31
) bar
where c22=c32 or (c222 is null and c22=0) or (c333 is null and c32=0);
&lt;/PRE&gt;&lt;P&gt;Result:&lt;/P&gt;&lt;PRE&gt;+------+--------+---------+----------+--+
|  c1  |   c2   |   c3    |    c4    |
+------+--------+---------+----------+--+
| 100  | Delta  | Source  | AppData  |
| 100  | Alpha  | Varied  | AppData  |
| 100  | Beta   | Volume  | AppData  |
| 100  | Owner  | NULL    | AppData  |
+------+--------+---------+----------+--+
&lt;/PRE&gt;</description>
      <pubDate>Wed, 24 May 2017 00:29:29 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/Hive-transpose-concatenated-data-in-columns-to-rows/m-p/181544#M61576</guid>
      <dc:creator>eberezitsky</dc:creator>
      <dc:date>2017-05-24T00:29:29Z</dc:date>
    </item>
    <item>
      <title>Re: Hive transpose concatenated data in columns to rows</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/Hive-transpose-concatenated-data-in-columns-to-rows/m-p/181545#M61577</link>
      <description>&lt;P&gt;&lt;A rel="user" href="https://community.cloudera.com/users/14209/eberezitsky.html" nodeid="14209"&gt;@Ed Berezitsky&lt;/A&gt; Thank you, this worked. &lt;/P&gt;</description>
      <pubDate>Thu, 25 May 2017 17:23:53 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/Hive-transpose-concatenated-data-in-columns-to-rows/m-p/181545#M61577</guid>
      <dc:creator>dhanya2kumar</dc:creator>
      <dc:date>2017-05-25T17:23:53Z</dc:date>
    </item>
    <item>
      <title>Re: Hive transpose concatenated data in columns to rows</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/Hive-transpose-concatenated-data-in-columns-to-rows/m-p/181546#M61578</link>
      <description>&lt;P&gt;&lt;A rel="user" href="https://community.cloudera.com/users/18497/dhanya2kumar.html" nodeid="18497"&gt;@Dhanya Kumar Heballi Shivamurthy&lt;/A&gt;, please accept the answer to close the thread.&lt;/P&gt;</description>
      <pubDate>Thu, 25 May 2017 20:27:41 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/Hive-transpose-concatenated-data-in-columns-to-rows/m-p/181546#M61578</guid>
      <dc:creator>eberezitsky</dc:creator>
      <dc:date>2017-05-25T20:27:41Z</dc:date>
    </item>
    <item>
      <title>Re: Hive transpose concatenated data in columns to rows</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/Hive-transpose-concatenated-data-in-columns-to-rows/m-p/181547#M61579</link>
      <description>&lt;P&gt;1)does a cross -join happen between c21 and c32?&lt;/P&gt;&lt;P&gt;2)why did you use select 100?&lt;/P&gt;&lt;P&gt;3)What is owner?&lt;/P&gt;</description>
      <pubDate>Tue, 28 Aug 2018 15:35:16 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/Hive-transpose-concatenated-data-in-columns-to-rows/m-p/181547#M61579</guid>
      <dc:creator>anjali_dnaik27</dc:creator>
      <dc:date>2018-08-28T15:35:16Z</dc:date>
    </item>
  </channel>
</rss>

