我在 Hive 中运行一个查询,如下所示,并且在左连接中有 OR 条件。当我运行选择时,它会抛出一些错误消息。
OR 目前在 JOIN 中不受支持(了解 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
我们怎样才能克服这个问题?
#For 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 次,这会影响查询。
感谢您花时间调查此事。