不支持 Hive 子查询

Hive Sub query not supporting

我们正在将 greenplum 迁移到 hive,下面的代码会为 hi​​ve 不支持的子查询创建问题。请帮助我。

转换的配置单元:

select concat_ws(';', max(concat_str)) 
FROM (
SELECT collect_list(Display_String) over (order by data_day ) concat_str 
FROM 
(select data_day, sum(revenue)/1000000.00 as revenue,data_day||' '||trim(regexp_replace(sum(revenue), '(?!^)(\d\d\d(?=(\d\d\d)*\b))', ',')) as Display_String 
from(select case when data_date = current_date  then 'D:' when data_date = date_sub(current_date,1) then ' D-01:'
when data_date = date_sub(current_date,2) then ' D-02:'
when data_date = date_sub(current_date,7) then ' D-07:'
when data_date = date_sub(current_date,28) then ' D-28:'
 end data_day, revenue/1000000.00 revenue
from test.tablename
where data_date between date_sub(current_date,28) and current_date and 
hour <=(Select hour from ( select row_number() over(order by hour desc) iRowsID, 
hour from test.tablename where data_date = current_date and  type = 'UVC')tbl1
where irowsid = 2) and type in( 'UVC')
order by 1 desc) a
group by 1) aa ) concat_qry

旧的 Greenplum 代码

select string_agg(Display_String, ';' order by data_day )
from
(
select data_day, 
sum(revenue)/1000000.00 as revenue,
data_day||' '||trim(to_char(sum(revenue),'9,999,999,999')) as Display_String 
from(
select case when data_date = current_date  then 'D:'
when data_date = current_date - 1 then ' D-01:'
when data_date = current_date - 2 then ' D-02:'
when data_date = current_date - 7 then ' D-07:'
when data_date = current_date - 28 then ' D-28:'
 end data_day, revenue/1000000.00 revenue
from test.tablename
where data_date between current_date - 28 and current_date and 
hour <=(Select hour from ( select row_number() over(order by hour desc) iRowsID, 
hour from test.tablename where data_date = current_date and  type = 'UVC')tbl1
where irowsid = 2) and type in( 'UVC')
order by 1 desc) a
group by 1)aa;

你能试试这个吗?

我做了左连接而不是子查询。我无法检查,因为我没有必要的表格。如果您发现任何问题,请告诉我。

select concat_ws(';', max(concat_str)) 
FROM (
SELECT collect_list(Display_String) over (order by data_day ) concat_str 
FROM 
(select data_day, sum(revenue)/1000000.00 as revenue,data_day||' '||trim(regexp_replace(sum(revenue), '(?!^)(\d\d\d(?=(\d\d\d)*\b))', ',')) as Display_String 
from(select case when data_date = current_date  then 'D:' when data_date = date_sub(current_date,1) then ' D-01:'
when data_date = date_sub(current_date,2) then ' D-02:'
when data_date = date_sub(current_date,7) then ' D-07:'
when data_date = date_sub(current_date,28) then ' D-28:'
 end data_day, revenue/1000000.00 revenue
from test.tablename
left join (Select hour hour_subq  from ( select row_number() over(order by hour desc) iRowsID, 
hour from test.tablename where data_date = current_date and  type = 'UVC')tbl1
where irowsid = 2)  rs ON hour <= rs.hour_subq  
where data_date between date_sub(current_date,28) and current_date 
and type in( 'UVC')
 ) a
group by 1) aa ) concat_qry