在 llap 中加入工作但不在配置单元中工作的配置单元查询

hive query with between in join working in llap but not in hive

带连接的低于范围的查询在 llap 中工作正常,但在 Hiveserver2/Hive.CLI 中不行。

请建议如何在 Hive 中使用范围连接查询。

配置单元版本:1.2.1.2.6

HDP 版本:2.6.0.3

查询:

select * from datahub.cgs_tmp_gre gre
INNER JOIN datahub.cgs_tmp_cgsrxclm_ev_ba ba
ON gre.guar_key = ba.guar_key and gre.serviced_dte = ba.serviced_dte
AND gre.ts between ba.obsv_start_ts and ba.obsv_stop_ts
AND gre.ts between ba.obsv_start_ts and ba.obsv_stop_ts
AND gre.phcy_claim_id=2;

下面是我们在 hive CLI 或 hive server 2 中 运行 时抛出的错误:

Error: Error while compiling statement: FAILED: SemanticException Line 0:-1 Both left and right aliases encountered in JOIN 'obsv_stop_ts' (state=42000,code=40000)

此错误是因为您有两次相同的 join 条件。 between 解析为 >=<=,不等式在 join 条件下不受支持(2.2.0 版之前)。将条件移动到 where 子句,它应该可以工作。

select * --specify required columns rather than *
from datahub.cgs_tmp_gre gre
INNER JOIN datahub.cgs_tmp_cgsrxclm_ev_ba ba
ON gre.guar_key = ba.guar_key and gre.serviced_dte = ba.serviced_dte
WHERE gre.ts >= ba.obsv_start_ts and gre.ts <= ba.obsv_stop_ts --replaced between with >= and <=
AND gre.phcy_claim_id=2;