<?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: Parsing multiple pipe delimited columns into rows with ID with Hive/Impala in Support Questions</title>
    <link>https://community.cloudera.com/t5/Support-Questions/Parsing-multiple-pipe-delimited-columns-into-rows-with-ID/m-p/349302#M235604</link>
    <description>&lt;P&gt;&lt;a href="https://community.cloudera.com/t5/user/viewprofilepage/user-id/93978"&gt;@Hafiz&lt;/a&gt;&amp;nbsp;Has the reply helped resolve your issue? If so, please mark the appropriate reply as the solution, as it will make it easier for others to find the answer in the future.&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 02 Aug 2022 05:41:42 GMT</pubDate>
    <dc:creator>VidyaSargur</dc:creator>
    <dc:date>2022-08-02T05:41:42Z</dc:date>
    <item>
      <title>Parsing multiple pipe delimited columns into rows with ID with Hive/Impala</title>
      <link>https://community.cloudera.com/t5/Support-Questions/Parsing-multiple-pipe-delimited-columns-into-rows-with-ID/m-p/346519#M234908</link>
      <description>&lt;P&gt;I have a table with an ID, key and 2 columns with each contains pipe separated values. How can i parse column into multiple rows with the respective values?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Table that I have:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE border="1" width="99.7159090909091%"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD width="25%"&gt;ID&lt;/TD&gt;&lt;TD width="25%"&gt;key&lt;/TD&gt;&lt;TD width="25%"&gt;itemno&lt;/TD&gt;&lt;TD width="25%"&gt;value&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="25%"&gt;1&lt;/TD&gt;&lt;TD width="25%"&gt;A&lt;/TD&gt;&lt;TD width="25%"&gt;1|2|3&lt;/TD&gt;&lt;TD width="25%"&gt;10|20|30&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="25%"&gt;1&lt;/TD&gt;&lt;TD width="25%"&gt;B&lt;/TD&gt;&lt;TD width="25%"&gt;1|2|3&lt;/TD&gt;&lt;TD width="25%"&gt;40|50|60&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="25%"&gt;1&lt;/TD&gt;&lt;TD width="25%"&gt;C&lt;/TD&gt;&lt;TD width="25%"&gt;1|2|3&lt;/TD&gt;&lt;TD width="25%"&gt;70|80|90&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Expected output:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE border="1" width="76.34499289772727%"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD width="25%" height="30px"&gt;ID&lt;/TD&gt;&lt;TD width="12.5%" height="30px"&gt;key&lt;/TD&gt;&lt;TD width="25%" height="30px"&gt;itemno&lt;/TD&gt;&lt;TD width="25%" height="30px"&gt;value&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="25%" height="30px"&gt;1&lt;/TD&gt;&lt;TD width="12.5%" height="30px"&gt;A&lt;/TD&gt;&lt;TD width="25%" height="30px"&gt;1&lt;/TD&gt;&lt;TD width="25%" height="30px"&gt;10&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="25%" height="30px"&gt;1&lt;/TD&gt;&lt;TD width="12.5%" height="30px"&gt;A&lt;/TD&gt;&lt;TD width="25%" height="30px"&gt;2&lt;/TD&gt;&lt;TD width="25%" height="30px"&gt;20&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="25%" height="30px"&gt;1&lt;/TD&gt;&lt;TD width="12.5%" height="30px"&gt;A&lt;/TD&gt;&lt;TD width="25%" height="30px"&gt;3&lt;/TD&gt;&lt;TD width="25%" height="30px"&gt;30&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="25%" height="30px"&gt;1&lt;/TD&gt;&lt;TD width="12.5%" height="30px"&gt;B&lt;/TD&gt;&lt;TD width="25%" height="30px"&gt;1&lt;/TD&gt;&lt;TD width="25%" height="30px"&gt;40&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="25%" height="30px"&gt;1&lt;/TD&gt;&lt;TD width="12.5%" height="30px"&gt;B&lt;/TD&gt;&lt;TD width="25%" height="30px"&gt;2&lt;/TD&gt;&lt;TD width="25%" height="30px"&gt;50&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="25%" height="30px"&gt;1&lt;/TD&gt;&lt;TD width="12.5%" height="30px"&gt;B&lt;/TD&gt;&lt;TD width="25%" height="30px"&gt;3&lt;/TD&gt;&lt;TD width="25%" height="30px"&gt;60&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="25%" height="30px"&gt;1&lt;/TD&gt;&lt;TD width="12.5%" height="30px"&gt;C&lt;/TD&gt;&lt;TD width="25%" height="30px"&gt;1&lt;/TD&gt;&lt;TD width="25%" height="30px"&gt;70&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="25%" height="30px"&gt;1&lt;/TD&gt;&lt;TD width="12.5%" height="30px"&gt;C&lt;/TD&gt;&lt;TD width="25%" height="30px"&gt;2&lt;/TD&gt;&lt;TD width="25%" height="30px"&gt;80&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD height="30px"&gt;1&lt;/TD&gt;&lt;TD height="30px"&gt;C&lt;/TD&gt;&lt;TD height="30px"&gt;3&lt;/TD&gt;&lt;TD height="30px"&gt;90&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Really appreciate the help!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Wed, 29 Jun 2022 09:19:03 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Support-Questions/Parsing-multiple-pipe-delimited-columns-into-rows-with-ID/m-p/346519#M234908</guid>
      <dc:creator>Hafiz</dc:creator>
      <dc:date>2022-06-29T09:19:03Z</dc:date>
    </item>
    <item>
      <title>Re: Parsing multiple pipe delimited columns into rows with ID with Hive/Impala</title>
      <link>https://community.cloudera.com/t5/Support-Questions/Parsing-multiple-pipe-delimited-columns-into-rows-with-ID/m-p/348665#M235422</link>
      <description>&lt;P&gt;&lt;a href="https://community.cloudera.com/t5/user/viewprofilepage/user-id/93978"&gt;@Hafiz&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am able to achieve it with posexplode, please find my solution below.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;create table comm_article(id int, key string, itemno string, value string);
insert into comm_article values(1, 'A', '1|2|3', '10|20|30'), (1, 'B', '1|2|3', '40|50|60'), (1, 'C', '1|2|3', '70|80|90');
select * from comm_article;
+------------------+-------------------+----------------------+---------------------+
| comm_article.id  | comm_article.key  | comm_article.itemno  | comm_article.value  |
+------------------+-------------------+----------------------+---------------------+
| 1                | A                 | 1|2|3                | 10|20|30            |
| 1                | B                 | 1|2|3                | 40|50|60            |
| 1                | C                 | 1|2|3                | 70|80|90            |
+------------------+-------------------+----------------------+---------------------+


with t as (select id, key, split(itemno, '[|]') as itemno_arr, split(value, '[|]') as value_arr from comm_article)
select id, key, itemno, value from t
lateral view posexplode(itemno_arr) myTable1 AS myCol1, itemno
lateral view posexplode(value_arr) myTable2 AS myCol2, value
where myCol1 = myCol2;

+-----+------+---------+--------+
| id  | key  | itemno  | value  |
+-----+------+---------+--------+
| 1   | A    | 1       | 10     |
| 1   | A    | 2       | 20     |
| 1   | A    | 3       | 30     |
| 1   | B    | 1       | 40     |
| 1   | B    | 2       | 50     |
| 1   | B    | 3       | 60     |
| 1   | C    | 1       | 70     |
| 1   | C    | 2       | 80     |
| 1   | C    | 3       | 90     |
+-----+------+---------+--------+&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If this helps to address your ask, please accept the solution.&lt;/P&gt;</description>
      <pubDate>Mon, 25 Jul 2022 07:21:41 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Support-Questions/Parsing-multiple-pipe-delimited-columns-into-rows-with-ID/m-p/348665#M235422</guid>
      <dc:creator>nramanaiah</dc:creator>
      <dc:date>2022-07-25T07:21:41Z</dc:date>
    </item>
    <item>
      <title>Re: Parsing multiple pipe delimited columns into rows with ID with Hive/Impala</title>
      <link>https://community.cloudera.com/t5/Support-Questions/Parsing-multiple-pipe-delimited-columns-into-rows-with-ID/m-p/349302#M235604</link>
      <description>&lt;P&gt;&lt;a href="https://community.cloudera.com/t5/user/viewprofilepage/user-id/93978"&gt;@Hafiz&lt;/a&gt;&amp;nbsp;Has the reply helped resolve your issue? If so, please mark the appropriate reply as the solution, as it will make it easier for others to find the answer in the future.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 02 Aug 2022 05:41:42 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Support-Questions/Parsing-multiple-pipe-delimited-columns-into-rows-with-ID/m-p/349302#M235604</guid>
      <dc:creator>VidyaSargur</dc:creator>
      <dc:date>2022-08-02T05:41:42Z</dc:date>
    </item>
  </channel>
</rss>

