Hive union all报错

Hive Union ALL报错:

下面仅仅是个例子。

SELECT * FROM phone_app_day a WHERE dt=20150815 and upper(a.app_name) = 'MUSIC'
UNION ALL
SELECT * FROM phone_app_day b WHERE dt=20150815 and upper(b.app_name)='WALLPAPER'

执行报错:FAILED: SemanticException 3:5 Top level UNION is not supported currently; use a subquery for the UNION. Error encountered near token 'TOK_ALLCOLREF'

原来hive不支持顶层union,update sum_sdk_phone_app_filter_day union all只能将union封装在子查询中。

正确的做法是:把所有UNION ALL子句放到sub-query中,并且给table加别名,如下:

SELECT * FROM(

SELECT * FROM phone_app_day a WHERE dt=20150815 and upper(a.app_name) = 'MUSIC'
UNION ALL
SELECT * FROM phone_app_day b WHERE dt=20150815 and upper(b.app_name)='WALLPAPER'

)temp



你可能感兴趣的:(Hive union all报错)