今天在写一个sql的时候,使用了hive的union all,运行时报错。
sql如下:
select dimension_name,dt,dtype_name,uv,new_uv,old_uv,pv,stay_time from temp_bi.uv union all select ‘平台‘ dimension_name ,dt ,app_platform dtype_name ,count(distinct mid) uv ,count(distinct case when is_new = 1 then mid end) new_uv ,count(distinct case when is_new = 0 then mid end) old_uv ,sum(pv_num) pv ,sum(stay_time) stay_time --停留时长(秒) from vipdw.dw_log_app_visit_ds1 where dt between get_dt_date(get_date(-1)) and get_dt_date(get_date(-1)) group by ‘平台‘ ,dt ,app_platform
报错信息如下:
FAILED: SemanticException 1:71 Top level UNION is not supported currently; use a subquery for the UNION. Error encountered near token ‘app_platform‘
hive不支持顶层的union all,使用子查询来解决即可:
select * from ( select dimension_name,dt,dtype_name,uv,new_uv,old_uv,pv,stay_time from temp_bi.uv union all select ‘平台‘ dimension_name ,dt ,app_platform dtype_name ,count(distinct mid) uv ,count(distinct case when is_new = 1 then mid end) new_uv ,count(distinct case when is_new = 0 then mid end) old_uv ,sum(pv_num) pv ,sum(stay_time) stay_time --停留时长(秒) from vipdw.dw_log_app_visit_ds1 where dt between get_dt_date(get_date(-1)) and get_dt_date(get_date(-1)) group by ‘平台‘ ,dt ,app_platform) a
hive union all报错,布布扣,bubuko.com
时间: 2024-10-12 04:15:25