2012-05-22 105 views
0

我正在嘗試在Hive中執行類似以下的操作。我如何在Hive中將列定義爲子查詢?這在Hive中可能嗎?作爲子查詢選擇的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

回答

8

相關子查詢中不支持的蜂房。 這樣的事情呢? (我沒有機會親自在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 
+0

謝謝!你讓我走上正軌。我不得不添加一個「通過i.SearchListingID組」來使其運行。 –