【发布时间】:2014-09-25 21:22:53
【问题描述】:
我有运行良好的 RDBMS 表和查询。我已将数据从 RDBMS 卸载到 HIVE 表。要在 HIVE 上运行现有查询,我们首先需要使它们与 HIVE 兼容。
让我们以选择项目列表中的子查询为例。它在语法上有效并且在 RDBMS 系统上运行良好。但它不适用于 HIVE 根据 HIVE manual ,Hive 仅在 FROM 和 WHERE 子句中支持子查询。
示例 1:
SELECT t1.one
,(SELECT t2.two
FROM TEST2 t2
WHERE t1.one=t2.two) t21
,(SELECT t3.three
FROM TEST3 t3
WHERE t1.one=t3.three) t31
FROM TEST1 t1 ;
示例 2:
SELECT a.*
, CASE
WHEN EXISTS
(SELECT 1
FROM tblOrder O
INNER JOIN tblProduct P
ON O.Product_id = P.Product_id
WHERE O.customer_id = C.customer_id
AND P.Product_Type IN (2, 5, 6, 9)
)
THEN 1
ELSE 0
END AS My_Custom_Indicator
FROM tblCustomer C
INNER JOIN tblOtherStuff S
ON C.CustomerID = S.CustomerID ;
示例 3:
Select component_location_id, component_type_code,
( select clv.LOCATION_VALUE
from stg_dev.component_location_values clv
where identifier_code = 'AXLE'
and component_location_id = cl.component_location_id ) as AXLE,
( select clv.LOCATION_VALUE
from stg_dev.component_location_values clv
where identifier_code = 'SIDE'
and component_location_id = cl.component_location_id ) as SIDE
from stg_dev.component_locations cl ;
我想知道选择项目列表中子查询的可能替代方案,以使其与 hive 兼容。显然,我将能够以 HIVE 格式转换现有查询。
非常感谢任何帮助和指导!
【问题讨论】:
-
谢谢大家,我已经添加了更多示例