hive union

hive中执行如下语句报错

hive> insert overwrite table test6 
    > SELECT t1.user_id, t2.sale_developer_id develop_staff_id, t2.eparchy_code FROM yudh_test3 t1 LEFT JOIN 
    > (SELECT DISTINCT a.DEV_CODE, a.SALE_DEVELOPER_ID, a.EPARCHY_CODE FROM ts_u_develop_rel a) t2 
    > ON (t1.develop_staff_id = t2.dev_code AND t1.EPARCHY_CODE = t2.eparchy_code) 
    > UNION ALL 
    > SELECT t1.user_id, t2.sale_developer_id develop_staff_id, t2.eparchy_code FROM yudh_test3 t1 LEFT JOIN ts_u_develop_rel t2 
    > ON (t1.develop_staff_id = t2.bss_developer_id AND t1.EPARCHY_CODE = t2.eparchy_code);

FAILED: SemanticException 2:79 Top level UNION is not supported currently; use a subquery for the UNION. Error encountered near token 'eparchy_code'

hive不支持顶层union,只能讲union放到子查询中。
正确做法如下:把所有union all放到子查询中,并给起别名:
INSERT overwrite TABLE test6 
SELECT t3.user_id, t3.develop_staff_id, t3.eparchy_code FROM (
SELECT t1.user_id, t2.sale_developer_id develop_staff_id, t2.eparchy_code FROM yudh_test3 t1 LEFT JOIN 
(SELECT DISTINCT a.DEV_CODE, a.SALE_DEVELOPER_ID, a.EPARCHY_CODE FROM ts_u_develop_rel a) t2 
ON (t1.develop_staff_id = t2.dev_code AND t1.EPARCHY_CODE = t2.eparchy_code) 
UNION ALL 
SELECT t1.user_id, t2.sale_developer_id develop_staff_id, t2.eparchy_code FROM yudh_test3 t1 LEFT JOIN ts_u_develop_rel t2 
ON (t1.develop_staff_id = t2.bss_developer_id AND t1.EPARCHY_CODE = t2.eparchy_code)) t3  



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值