将数据拆分成Hive中的多个列 [英] Splitting data into multiple columns in Hive

查看:3415
本文介绍了将数据拆分成Hive中的多个列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



输入数据示例: 116:151:1

如何将数据字符串拆分为Hive表中的3个独立列? / code>。拆分为 gid,sid,rid



需要的输出:

  gid sid rid 
116 151 1


解决方案使用 split()函数。您可以在文档中阅读它(以及所有其他Hive函数) 。



查询

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

输出

  gid sid rid 
116 151 1

您需要替换116:151:1 与表格中列的名称。


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

解决方案

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.

这篇关于将数据拆分成Hive中的多个列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆