侧视图列可以具有相同的名称吗?

时间:2014-11-25 08:08:19

标签: sql hive

在Hive中,我有一个包含两列的表: uid (这是一个字符串)和 attr (这是一个地图)。

地图列包含联系人联系人的键,两者的值均为 18511111111 18522222222 185211111 等字符串。我想得到下表:

uid phone

我尝试了以下sql:

select
  uid,
  phone
from
  onetalbe
lateral view explode(split(attr['contacts'], ' ')) t1 as phone
lateral view explode(split(attr['contact'], ' ')) t2 as phone
where
  length(phone)==11 and phone like '1%'

但是我得到了错误:

java.sql.SQLException: Error while compiling statement: FAILED: SemanticException Column phone Found in more than One Tables/Subqueries at org.apache.hive.jdbc

那么有没有办法实现这个目标?提前谢谢。

1 个答案:

答案 0 :(得分:0)

 Actually there are 2 columns regarding phone, so it is giving error.  


   select uid, t1phone, t2phone
   from onetalbe 
   lateral view explode(split(attr['contacts'], ' ')) t1 as t1phone
   lateral view explode(split(attr['contact'], ' ')) t2 as t2phone 
   where length(phone)==11 and t1phone like '1%' and t2phone  like '1%'

    select uid, phone
       from onetalbe 
       lateral view explode(split(attr['contacts'], ' ')) t1 as phone
       where length(phone)==11 and phone like '1%' 
UNION ALL
       select uid, phone
       from onetalbe 
       lateral view explode(split(attr['contact'], ' ')) t1 as phone
       where length(phone)==11 and phone like '1%'