這篇文章主要介紹hive如何實(shí)現(xiàn)行轉(zhuǎn)列,文中介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們一定要看完!
創(chuàng)新互聯(lián)公司專注為客戶提供全方位的互聯(lián)網(wǎng)綜合服務(wù),包含不限于成都網(wǎng)站制作、成都做網(wǎng)站、外貿(mào)營(yíng)銷(xiāo)網(wǎng)站建設(shè)、祿勸網(wǎng)絡(luò)推廣、微信小程序、祿勸網(wǎng)絡(luò)營(yíng)銷(xiāo)、祿勸企業(yè)策劃、祿勸品牌公關(guān)、搜索引擎seo、人物專訪、企業(yè)宣傳片、企業(yè)代運(yùn)營(yíng)等,從售前售中售后,我們都將竭誠(chéng)為您服務(wù),您的肯定,是我們最大的嘉獎(jiǎng);創(chuàng)新互聯(lián)公司為所有大學(xué)生創(chuàng)業(yè)者提供祿勸建站搭建服務(wù),24小時(shí)服務(wù)熱線:028-86922220,官方網(wǎng)址:jinyejixie.com
1。問(wèn)題
hive如何將
a b 1,2,3
c d 4,5,6
變?yōu)椋?/p>
a b 1
a b 2
a b 3
c d 4
c d 5
c d 6
答案如下:
2。原始數(shù)據(jù):
test.txt
a b 1,2,3
c d 4,5,6
3。解決方法
方案1:
drop table test_jzl_20140701_test;
create table test_jzl_20140701_test
(
col1 string,
col2 string,
col3 string
)
row format delimited fields terminated by ' '
stored as textfile;
load data local inpath '/home/jiangzl/shell/test.txt' into table test_jzl_20140701_test;
select * from test_jzl_20140701_test
a b 1,2,3
c d 4,5,6
遍歷數(shù)組中的每一列
select col1,col2,name
from test_jzl_20140701_test
lateral view explode(split(col3,',')) col3 as name;
a b 1
a b 2
a b 3
c d 4
c d 5
c d 6
方案2:
drop table test_jzl_20140701_test1;
create table test_jzl_20140701_test1
(
col1 string,
col2 string,
col3 array<int>
)
row format delimited
fields terminated by ' '
collection items terminated by ',' //定義數(shù)組的分隔符
stored as textfile;
load data local inpath '/home/jiangzl/shell/test.txt' into table test_jzl_20140701_test1;
select * from test_jzl_20140701_test1;
a b [1,2,3]
c d [4,5,6]
遍歷數(shù)組中的每一列
select col1,col2,name
from test_jzl_20140701_test1
lateral view explode(col3) col3 as name;
a b 1
a b 2
a b 3
c d 4
c d 5
c d 6
4。補(bǔ)充知識(shí)點(diǎn):
select * from test_jzl_20140701_test;
a b 1,2,3
c d 4,5,6
select t.list[0],t.list[1],t.list[2] from (
select (split(col3,',')) list from test_jzl_20140701_test)t;
OK
1 2 3
4 5 6
--查看數(shù)組長(zhǎng)度
select size(split(col3,',')) list from test_jzl_20140701_test;
3
3
以上是“hive如何實(shí)現(xiàn)行轉(zhuǎn)列”這篇文章的所有內(nèi)容,感謝各位的閱讀!希望分享的內(nèi)容對(duì)大家有幫助,更多相關(guān)知識(shí),歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道!
網(wǎng)站標(biāo)題:hive如何實(shí)現(xiàn)行轉(zhuǎn)列
標(biāo)題網(wǎng)址:http://jinyejixie.com/article32/ppjhpc.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供定制網(wǎng)站、軟件開(kāi)發(fā)、網(wǎng)站設(shè)計(jì)、動(dòng)態(tài)網(wǎng)站、標(biāo)簽優(yōu)化、搜索引擎優(yōu)化
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)