简体   繁体   中英

Merge columns in hive

I am new to hive. Please help with my below problem.

I have below table in hive with one column having data with | as delimeter.

C1
1|2|3|4|5|6
7||9|10|11|12

The below one is expected output based on delimeter i want to split it as columns.

C1    C2   C3  C4  C5  C6
1     2    3   4   5   6
7          9   10  11  12

I have tried with locate and substr functions and endup with complex sql query. can you people help me in a simple way to do this.

Thank you!

Use split which returns an array of values from which individual elements can be selected as columns.

select split(c1,'\\|')[0] as c1
      ,split(c1,'\\|')[1] as c2
      ,split(c1,'\\|')[2] as c3
      ,split(c1,'\\|')[3] as c4
      ,split(c1,'\\|')[4] as c5
      ,split(c1,'\\|')[5] as c6
from tbl

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM