hive sql报错FAILED: SemanticException Line 0:-1 Both left and right aliases encountered in JOIN

在hql脚本时报错FAILED: SemanticException Line 0:-1 Both left and right aliases encountered in JOIN ,由于连接条件导致hql不能执行,网上查到了解决办法https://stackoverflow.com/questions/39852325/both-left-and-right-aliases-encountered-in-hive-join-without-any-inequality-cla;

这个问题的解决是将连接条件放入where条件中;

select * from a left join b on a.x = b.x and a.y = b.y

报错原因是第二个连接条件,改为

select * from a left join b on a.x = b.x
where a.y = b.y

hql可以正常执行但是仔细看一下这个替代hql会发现其查询结果会有细微的差别,由于是left join 左边表的数据应该是全的,但是第二种方式会导致右边有y左边没有y的结果被过滤掉;

解决办法:在where条件中添加条件补救

select * from a left join b on a.x = b.x
where a.y= b.y or b.y is null

 

你可能感兴趣的:(hive)