在Hive中联接多个表时,无效的表别名

时间:2019-07-23 23:29:50

标签: join hive

有人可以确定为什么不接受此多表联接吗?当我引入第三个表时,它将以无效的表别名失败。我看不出有什么问题:

这有效(两个表):

select  
 a.ri as `R_ID`
,oc3.name as `RET`
,a.rch as `RC`
from dev.sl a join dev.codes oc3 
    on (a.pk_business = oc3.pk_business 
    and a.pk_data_source = oc3.pk_data_source 
    and a.pk_frequency = oc3.pk_frequency 
    and oc3.pk_data_state = '123'
    and oc3.code = a.ri and oc3.codeset = 'xyz') 

然后添加第三个表,它将失败: (三张桌子):

select  
 a.ri as `R_ID`
,oc3.name as `RET`
,a.rch as `RC`
from dev.sl a join dev.codes oc3 
    on (a.pk_business = oc3.pk_business 
    and a.pk_data_source = oc3.pk_data_source 
    and a.pk_frequency = oc3.pk_frequency 
    and oc3.pk_data_state = '123'
    and oc3.code = a.ri and oc3.codeset = 'xyz') join dev.items b 
on (b.pk_business = a.pk_business 
and b.pk_data_source = a.pk_data_source 
and b.pk_frequency = a.pk_frequency 
and b.pk_data_state = '123' 
and a.ii = b.item_id 
and a.cc = b.country_code) 

SemanticException [错误10009]:行1:2920无效的表别名'a':

2 个答案:

答案 0 :(得分:0)

我有一个更新-看来这是由于将一个表创建为可更新表(TBLPROPERTIES('transactional'='true')),而另一个表却没有,并且我的会话设置为:

SET hive.txn.manager=org.apache.hadoop.hive.ql.lockmgr.DbTxnManager;
SET hive.support.concurrency=true;
SET hive.enforce.bucketing=true;
SET hive.exec.dynamic.partition.mode=nonstrict;

这引起了问题。在没有设置并指向创建为非ACID类型表的相同表“ a”的另一个会话上,多表联接工作正常。我对HIVE知之甚少,不知道为什么-我怀疑不能将事务和非事务表合并到同一“事务”(选择语句)中。

答案 1 :(得分:0)

又一次更新-可能不是由于事务表。通过其他测试,我现在也看到非事务表也发生了这种情况。当我直接在服务器上的腻子会话中执行三个表联接时,似乎可以正常工作,但是当我使用SQL Developer时,它将产生上述错误。这似乎是SQL Developer的问题,但为什么仍然未知。