我正在 Hive 中运行一个查询,如下所示,并且在左连接中有 OR 条件。当我运行选择时,它会向我抛出一些错误消息。
-
OR 目前在 JOIN 中不支持(了解 OR 仅适用于 Hive 中的等值连接)
-
JOIN 'cre_timestamp' 中同时遇到左右别名
a.line_id,
a.seller,
a.sellerid,
a.sellername,
a.item_no,
a.item_cd,
a.cre_timestamp
from Table A
left join Table B
on translate(a.id,'0','') = translate(b.id,'0','')
or translate(a.seller,'Z','') = translate(b.seller,'Z','')
or (a.item_no=b.item_no and a.item_no is not null and a.item_cd is not null and a.item_no <> '' and a.item_cd <> '')
left join ( select id, line_id,cre_timestamp from table x) C
on a.id=c.id
and a.cre_timestamp < c.cre_timestamp
and a.cre_timestamp > date_sub(c.cre_timestamp,21)
and translate(a.id,'0','') = translate(b.id,'0','') or a.item_cd = b.item_cd
where a.seller is null
我们怎样才能克服这个问题呢?
#对于1:
我可以尝试编写查询的一种方法是,使用 UNION,针对 OR 条件复制查询 3 次。
#For 2:
如果我把
and a.cre_timestamp < c.cre_timestamp
and a.cre_timestamp > date_sub(c.cre_timestamp,21)
并将其带入where
底部的条款,效果很好。 (想了解为什么它在连接中不起作用)
总的来说,寻找一种更好的方法,不会影响运行时并且更优化查询,就好像我将其更改为使用UNION一样,它必须处理相同的查询3次,这会影响查询。
感谢您花时间调查此事。