Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Splitting data into multiple columns in Hive

Tags:

split

hive

How can I split a data string into 3 separate columns in a Hive table?

Example input data: 116:151:1. Split as gid, sid, rid.

Required output:

gid    sid     rid
116    151     1
like image 809
vanj Avatar asked Dec 08 '22 00:12

vanj


1 Answers

Use the split() function. You can read about it (and all other Hive functions) in the documentation.

Query:

select split("116:151:1", '\\:')[0] as gid
     , split("116:151:1", '\\:')[1] as sid
     , split("116:151:1", '\\:')[2] as rid
from database.table

Output:

gid    sid    rid
116    151    1

You'll want to replace "116:151:1" with the name of the column in your table.

like image 55
o-90 Avatar answered Dec 17 '22 08:12

o-90