不支持 Hive 子查询
Posted
技术标签:
【中文标题】不支持 Hive 子查询【英文标题】:Hive Sub query not supporting 【发布时间】:2021-09-28 05:32:21 【问题描述】:我们正在将 greenplum 迁移到 hive 和以下代码,从而为 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
旧的 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;
【问题讨论】:
【参考方案1】:你能试试这个吗?
我做了一个左连接而不是子查询。我无法检查,因为我没有必要的表格。如果您发现任何问题,请告诉我。
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
【讨论】:
列引用“小时”不明确¶ -- 错误 你能试试新的sql吗?我在子查询中给它起了别名。 左连接(选择小时从(选择 row_number() over(order by hour desc) iRowsID,小时从 playground_mkt1.rpt_hourly_sub_sms where data_date = current_date and type = 'UVC') tbl1 where irowsid = 2) rs ON 小时 我必须在哪里给出 alise tbl1.hour以上是关于不支持 Hive 子查询的主要内容,如果未能解决你的问题,请参考以下文章