如何将分号分隔的数据拆分到配置单元中的列并转置它?
How to split semicolon separated data to columns in hive and also transpose it?
我在配置单元中有以下格式的数据集 table。
<br><b>|Col_1 | Col_2 |Col_3</b></<br>
<br>|abc_1 | a;b;c;d |m;n</br>
<br>|abc_2 | e;f;d |l;h;p<br>
我需要将数据转换成下面的格式。
<br><b>|Col_1 | Col_2_OR_3 |Value</b></<br>
<br>|abc_1 | Col_2 | a</br>
<br>|abc_1 | Col_2 | b</br>
<br>|abc_1 | Col_2 | c</br>
<br>|abc_1 | Col_2 | d</br>
<br>|abc_1 | Col_3 | m</br>
<br>|abc_1 | Col_3 | n</br>
<br>|abc_2 | Col_2 | e</br>
<br>|abc_2 | Col_2 | f</br>
<br>|abc_2 | Col_2 | d</br>
<br>|abc_2 | Col_3 | l</br>
<br>|abc_2 | Col_3 | h</br>
<br>|abc_2 | Col_3 | p</br>
数据最初在 Col_1 中的值是唯一的。Col_2 中的分号分隔值和Col_3需要分开转置为新列Value并且需要创建另一列Col_2_OR_3 具有从 Col_2 或 Col_3.
select col_1,'Col_2',col_2_al
from <table_name>
lateral view explode(split(col_2, "\\;")) col_2_al as col_2_al
union all
select col_1,'Col_3',col_2_al
from <table_name>
lateral view explode(split(col_3,"\\;")) col_3_al as col_2_al
我在配置单元中有以下格式的数据集 table。
<br><b>|Col_1 | Col_2 |Col_3</b></<br>
<br>|abc_1 | a;b;c;d |m;n</br>
<br>|abc_2 | e;f;d |l;h;p<br>
我需要将数据转换成下面的格式。
<br><b>|Col_1 | Col_2_OR_3 |Value</b></<br>
<br>|abc_1 | Col_2 | a</br>
<br>|abc_1 | Col_2 | b</br>
<br>|abc_1 | Col_2 | c</br>
<br>|abc_1 | Col_2 | d</br>
<br>|abc_1 | Col_3 | m</br>
<br>|abc_1 | Col_3 | n</br>
<br>|abc_2 | Col_2 | e</br>
<br>|abc_2 | Col_2 | f</br>
<br>|abc_2 | Col_2 | d</br>
<br>|abc_2 | Col_3 | l</br>
<br>|abc_2 | Col_3 | h</br>
<br>|abc_2 | Col_3 | p</br>
数据最初在 Col_1 中的值是唯一的。Col_2 中的分号分隔值和Col_3需要分开转置为新列Value并且需要创建另一列Col_2_OR_3 具有从 Col_2 或 Col_3.
select col_1,'Col_2',col_2_al
from <table_name>
lateral view explode(split(col_2, "\\;")) col_2_al as col_2_al
union all
select col_1,'Col_3',col_2_al
from <table_name>
lateral view explode(split(col_3,"\\;")) col_3_al as col_2_al