lateral view explode使用

lateral view 侧视图   explode 爆炸               

 

select wdmc,customer_id from(
select 1 as wdmc,'14590170|14587203|21396385|22105752' as qyid
)a lateral view explode(split(qyid,'|')) as customer_id

报错:

Error while compiling statement: FAILED: ParseException line 5:44 extraneous input 'customer_id' expecting EOF near '<EOF>'

侧视图本质是left join,  explode 之后就是 右表了,原表为坐标

而左右两表 都需要  命名

正确的写法: 多了一个b(侧视图命名) 而已

select wdmc,customer_id from(
select 1 as wdmc,"14590170|14587203|21396385|22105752" as qyid
)a lateral view explode(split(qyid,"|"))b as customer_id

但结果有问题,我想用‘|’隔开  但结果是:

 wdmccustomer_id
111
214
315
419
510
611
717
810
91|
1011
1114
1215
1318

...

尝试单独使用explode:

select explode(split("14590170|14587203|21396385|22105752","|")) as id

 结果一样:

 id
11
24
35
49
50
61
77
80
9|
101
114
125
138
147
152

split有问题 

describe function split
 tab_name
1split(str, regex) - Splits str around occurances that match regex

后来慢慢分析,原来是转义有问题,单独一个  ‘|’   在 hive中可能是别的含义,我们需要转义‘|’ 让hive知道我要的就是 ‘|’用它,

但是  ‘\|’ 其实这样也是错的,因为 ‘\’ 在hive中也有别的意思,所以,我们要将斜杠  ‘\’  先转义成  真斜杠

select explode(split("14590170|14587203|21396385|22105752","\\|")) as id

 

 id
114590170
214587203
321396385
422105752

再搭配 侧视图  lateral view 

select wdmc,customer_id from(
select 1 as wdmc,"14590170|14587203|21396385|22105752" as qyid
)a lateral view explode(split(qyid,"\\|"))b as customer_id

 

结果完美:

 wdmccustomer_id
1114590170
2114587203
3121396385
4122105752
 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值