we are migrating greenplum to hive and below code creating issues for sub query not supported by hive. please help me.
converted hive:
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))', ',$1')) 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
old Greenplum code
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;
could you pls try this ?
I did a left join instead of subquery. I couldn't check because i dont have necessary tables. pls let me know if you see any issues.
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))', ',$1')) 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