Hive 中的以下代码是否可能,并进行一些更改?:
insert into table webmap
select a.res reference, b.res resource,
(select count(ip) from weblog where resource=a.res and referer=b.res) weight
from toprefres a join toprefres b;
我在 hive-0.10.0-cdh4.5.0 中运行它并得到错误:
FAILED: ParseException line 3:1 cannot recognize input near 'select' 'count' '(' in expression specification
如果支持select in select in Hive呢!
我终于找到答案了:
insert into table webmap
select refres.reso,refres.refe, count(ip) weight from
weblog join (select a.res refe, b.res reso from toprefres a join toprefres b) refres on
trimrslash(weblog.resource)=refres.reso and trimrslash(weblog.referrer)=concat("http://dongxicheng.org",refres.refe)
group by refres.reso,refres.refe;
这非常适合我的需要!
最佳答案
据我所知,Hive 不支持此类相关子查询。我从以下帖子中证实了我的想法:
Hive column as a subquery select
无论我怎么想,您都可以修改查询以实现您想要获得的结果:
insert into table webmap
select a.res reference, b.res resource,
count(weblog.ip) weight
from toprefres a
join toprefres b
join weblog ON weblog.resource=a.res
and weblog.referer=b.res;
另请注意,您的 ON 子句中没有这可能会导致交叉联接创建笛卡尔积并花费更多时间。如果可能,请尝试对其进行优化。
关于sql - Hive是否支持Select中的Select?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22059559/