Splitting data into multiple columns in Hive

安稳与你 提交于 2019-12-10 09:46:54

问题


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

回答1:


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.



来源:https://stackoverflow.com/questions/34130104/splitting-data-into-multiple-columns-in-hive

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!