1

I'm trying to do something like below with Hive. How can I have a column in Hive be defined as a subquery? Is this possible in Hive?

hive -e "           
select
distinct i.SearchListingID,
(select count(*) 
    from calls c 
    where c.ServiceID = i.SearchListingID
    ) as CallsCount
from Impressions i
where i.yyyymmdd = 20120401
limit 10" > ImpressionCalls.txt

Hive history file=/tmp/jd/hive_job_log_jd_201205222049_550931420.txt

FAILED: Parse Error: line 4:1 cannot recognize input near 'select' 'count' '(' in expression specification

4

1 回答 1

9

Hive 不支持相关子查询。像这样的东西怎么样?(我自己没有机会在 Hive 上验证此查询)

select
    i.SearchListingID,
    count(*)
from
    (
    select
         distinct i.SearchListingID as SearchListingID 
    from 
        Impressions i
    where
        i.yyyymmdd = 20120401
    )i
    join
    calls c
    on(c.ServiceID = i.SearchListingID)
limit 10
于 2012-05-23T03:37:46.900 回答