【发布时间】:2021-01-15 20:07:12
【问题描述】:
我正在 Hive 中运行一个查询,如下所示,并且在左连接中有 OR 条件。当我运行选择时,它会抛出一些错误消息。
-
目前在 JOIN 中不支持 OR(了解 OR 仅适用于 Hive 中的 equi 联接)
-
在 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 将查询复制 3 次,用于 OR 条件。
#2:
如果我剪掉了
and a.cre_timestamp < c.cre_timestamp
and a.cre_timestamp > date_sub(c.cre_timestamp,21)
并将其放入底部的where 子句中,它可以正常工作。 (想了解为什么它在连接中不起作用)
总的来说,寻找更好的方法,不会影响运行时和更优化的查询,如果我将它更改为使用UNION,它必须处理相同的查询3次,这会影响查询.
感谢您抽出宝贵时间对此进行调查。
【问题讨论】:
标签: sql join hive hiveql non-equi-join