2017-01-28 94 views
0

假設我有兩個分區表,分別爲customeritems,並且這兩個分區表均由countrystate列進行分區。在Hive中加入分區表

鑑於我想要檢索特定國家和州的數據,這是加入這些表格的正確方法嗎?

select 
    customer.id, 
    customer.name, 
    items.name, 
    items.value 
from 
    customers 
    join items 
    on customers.id == items.customer_id 
    and customers.country == 'USA' 
    and customers.state == 'TX' 
    and items.country == 'USA' 
    and items.state == 'TX' 

還是應該將這些條件放在WHERE子句中?

and customers.country == 'USA' 
and customers.state == 'TX' 
and items.country == 'USA' 
and items.state == 'TX' 
+1

這些條件應該放在WHERE子句中。 – highlycaffeinated

回答

1

對於簡單的查詢,蜂巢將推謂語前減少階段,所以在這種情況下,表現將是把條件對「上」或「在哪裏」的條款之間的相同。但是,如果您在其他查詢中比較表之間的字段(table1.a < table2.b),則Hive將執行連接並在最後(reducer階段)應用where條件,就像大多數關係數據庫一樣。