Impala 版本 :3.2.0+cdh6.3.2
在impala sql中使用 “having “时,出现了 “could not resolve column/field reference “的错误。
select count(dst_ip) as times, dst_ip
from test_mode
group by dst_ip
having times > 1
我不知道为什么,impala文档支持有https://impala.apache.org/docs/build/html/topics/impala_group_by.html#group_by
如下图:
检查你的impala版本,移动到上层目录,找到正确的文档。https://impala.apache.org/docs/build/
例如,apache impala guide(impala-3.4.pdf)在 “Overview of Impala Aliases “中说。
从impala 3.0 开始,在group by、having和order by子句中的别名替换逻辑变得更加符合标准的行为,如下所示。别名现在只在顶层合法,而不是在subexpressions中。
SELECT int_col / 2 AS x FROM t GROUP BY x;
SELECT int_col / 2 AS x FROM t ORDER BY x;
SELECT NOT bool_col AS nb FROM t GROUP BY nb HAVING nb;
和以下语句是不允许的。
SELECT int_col / 2 AS x FROM t GROUP BY x / 2;
SELECT int_col / 2 AS x FROM t ORDER BY -x;
SELECT int_col / 2 AS x FROM t GROUP BY x HAVING x > 3;
文档第197页:
在你的sql中,”times > 1 “是一个子表达式,”having times > 1 “在impala 3.0或更高版本中是不可接受的
所以我的另外一个SQL改为:
SELECT
NOT fnv_hash(a.cmp_rt_tm)=fnv_hash(b.cmp_rt_tm) as tt,
fnv_hash(a.sal_amt_td)=fnv_hash(b.sal_amt_td) as tw,
fnv_hash(a.sal_amt_tm)=fnv_hash(b.sal_amt_tm) as th
FROM ods_ivs_co_rpt_day_kudu a
LEFT JOIN ods_ivs_co_rpt_day_text b
ON a.`date` = b.`date` AND a.ind_co_name = b.ind_co_name
HAVING tt