Hive UNION ALL 提示 Schema of both sides of union should match.

来源:互联网 发布:南京数据分析招聘 编辑:程序博客网 时间:2024/05/22 09:06

感谢分享:http://blog.csdn.net/jinjiating/article/details/18009503

select * from
(select tokenid 
from sm_play where dt=140108
union all
select device_token 
from mda_dbs_passport_device)tmp;

FAILED: SemanticException 6:5 Schema of both sides of union should match. tmp-subquery2 does not have the field tokenid. Error encountered near token 'mda_dbs_passport_device'

原因:union all两边表的列名不一致

select * from
(select tokenid 
from sm_play where dt=140108
union all
select device_token as tokenid
from mda_dbs_passport_device)tmp;



我的语句:
CREATE VIEW IF NOT EXISTS xxx.xxx AS
SELECT 
   a.xxx AS aaa,
   b.xxx AS bbb
FROM xxx a
LEFT JOIN xxx b
UNION ALL

SELECT 

  NULL,

  c.xxx

FROM xxx c

改成

CREATE VIEW IF NOT EXISTS xxx.xxx AS
SELECT 
   a.xxx AS aaa,
   b.xxx AS bbb
FROM xxx a
LEFT JOIN xxx b
UNION ALL

SELECT 

  NULL AS aaa,

  c.xxx AS bbb

FROM xxx c


原创粉丝点击