Hive Query- Joining two tables on three joining conditions with OR operator

后端 未结 2 1455
情歌与酒
情歌与酒 2020-12-31 09:43

I am facing an error

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

while running the below mentione

相关标签:
2条回答
  • 2020-12-31 10:20

    You could also use UNION to get the same results:

    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;
    
    0 讨论(0)
  • 2020-12-31 10:23

    Sorry Hive supports only equi-joins. You can always try select from full Cartesian product of those tables(you have to be in non-strict mode):

    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;
    
    0 讨论(0)
提交回复
热议问题