2013-04-29 76 views
9

我面臨着一個錯誤蜂巢查詢 - 三個加盟與操作條件或連接兩個表

FAILED: Error in semantic analysis: Line 1:101 OR not supported in JOIN currently dob

在運行下面提到的查詢..

Insert Overwrite Local Directory './Insurance_Risk/Merged_Data' Select f.name,s.age,f.gender,f.loc,f.marital_status,f.habits1,f.habits2,s.employement_status,s.occupation_class,s.occupation_subclass,s.occupation from sample_member_detail s Join fb_member_detail f 
On s.email=f.email or 
s.dob=f.dob 
or (f.name=s.name and f.loc = s.loc and f.occupation=s.occupation) 
where s.email is not null and f.email is not null; 

誰能告訴我認爲,在蜂房「OR」運營商可以使用或不? 如果不是,那麼應該是什麼樣的查詢將給出與上述查詢給出的結果相同的結果。 我有2個表,我想加入兩個表中的任何一個與運算符的三個條件。 請幫忙..

回答

7

對不起Hive只支持equi連接。你可以嘗試從(你必須在非嚴格模式)這些表的全笛卡爾積選擇:

Select f.name,s.age,f.gender,f.loc,f.marital_status,f.habits1,f.habits2,s.employement_status,s.occupation_class,s.occupation_subclass,s.occupation 
from sample_member_detail s join fb_member_detail f 
where (s.email=f.email 
or s.dob=f.dob 
or (f.name=s.name and f.loc = s.loc and f.occupation=s.occupation)) 
and s.email is not null and f.email is not null; 
5

你也可以使用UNION來得到相同的結果:

INSERT OVERWRITE LOCAL DIRECTORY './Insurance_Risk/Merged_Data' 
-- You can only UNION on subqueries 
SELECT * FROM (
    SELECT f.name, 
     s.age, 
     f.gender, 
     f.loc, 
     f.marital_status, 
     f.habits1, 
     f.habits2, 
     s.employement_status, 
     s.occupation_class, 
     s.occupation_subclass, 
     s.occupation 
    FROM sample_member_detail s 
    JOIN fb_member_detail f 
    ON s.email=f.email 
    WHERE s.email IS NOT NULL AND f.email IS NOT NULL; 

    UNION 

    SELECT f.name, 
     s.age, 
     f.gender, 
     f.loc, 
     f.marital_status, 
     f.habits1, 
     f.habits2, 
     s.employement_status, 
     s.occupation_class, 
     s.occupation_subclass, 
     s.occupation 
    FROM sample_member_detail s 
    JOIN fb_member_detail f 
    ON s.dob=f.dob 
    WHERE s.email IS NOT NULL AND f.email IS NOT NULL; 

    UNION 

    SELECT f.name, 
     s.age, 
     f.gender, 
     f.loc, 
     f.marital_status, 
     f.habits1, 
     f.habits2, 
     s.employement_status, 
     s.occupation_class, 
     s.occupation_subclass, 
     s.occupation 
    FROM sample_member_detail s 
    JOIN fb_member_detail f 
    ON f.name=s.name AND f.loc = s.loc AND f.occupation=s.occupation 
    WHERE s.email IS NOT NULL AND f.email IS NOT NULL; 

) subquery; 
+1

你會必須在外層添加_distinct_以獲得相同的結果。否則,您將得到滿足多個條件的行的重複項。 – 2014-05-02 18:34:06