Conditional join in Hive

I want to execute below request in Hive -

select * from supp a inner join trd_acct b
on
(a.btch_id = 11170 AND a.btch_id = b.btch_id)
OR (a.btch_id = 11164 AND a.supp_id = b.supp_id)

But getting the error is

FAILED: SemanticException [Error 10019]: String 3: 1 OR is not supported in the JOIN currently "supp_id"

+4
source share
2 answers

You can solve this with UNION:

select * from supp a inner join trd_acct b
 on a.btch_id = 11170 AND a.btch_id = b.btch_id
UNION ALL
select * from supp a inner join trd_acct b
 on a.btch_id = 11164 AND a.supp_id = b.supp_id

Or you can try CASE EXPRESSION:

select * from supp a
inner join trd_acct b
 on CASE WHEN a.btch_id = 11164 THEN a.supp_id 
         WHEN a.btch_id = 11170 THEN a.btch_id END
  = CASE WHEN a.btch_id = 11164 THEN b.supp_id
         WHEN a.btch_id = 11170 then b.btch_id END
+4
source

Below in the file "Hive" (Hadoop) the request works fine

select * from supp a inner join trd_acct b
where
(a.btch_id = 11170 AND a.btch_id = b.btch_id)
OR (a.btch_id = 11164 AND a.supp_id = b.supp_id)

I tested in the Hive console.

+1
source

Source: https://habr.com/ru/post/1653652/


All Articles