hive中执行sql报错:FAILED: SemanticException The abstract syntax tree is null
执行sql为:
set hive.cli.print.header=true;
with t as(
select 1 id,'k1' key,123 value
union all
select 1 id,'k2' key,124 value
union all
select 2 ,'k1' key,234 value
)
select id,
max(case when key='k1' then value else 0 end) k1,
sum(case when key='k2' then value else 0 end) k2
from t
group by id;
排查为union all 前后的select语句中字段必须有相同的字段名,将select 2 ,'k1' key,234 value 改为select 2 id ,'k1' key,234 value 即可
本文介绍了在Hive中执行SQL时遇到的 SemanticException The abstract syntax tree is null 错误。问题根源在于union all操作前后select语句的字段名称不一致。解决方法是确保所有select子句具有相同的字段名。通过修正select2,'k1'key,234value为select2 id,'k1'key,234value,问题得到解决。此案例对于理解和排查Hive SQL语法错误具有参考价值。

被折叠的 条评论
为什么被折叠?



