sake
sake

Reputation: 125

hive left outer join with between condition

I know we can't do un-equal joins in hive. I need to convert below query in to hive (hql). Any suggestions/workaround's would be appreciated.

Both table_A and table_B dose not have primary key.

SELECT * 
FROM table_A f
LEFT OUTER JOIN table_B dom1
 ON dom1.country = f.issuing_office_country
AND dom1.ulr_source = 'Loss'
AND dom1.valuation_class = f.dsp_level_join
AND dom1.year_type = 'UW'
AND f.undwrtr_yr_prd_fy_mnth BETWEEN dom1.start_year_month AND dom1.end_year_month

LEFT OUTER JOIN table_B dom2
 ON dom2.country = f.issuing_office_country
AND dom2.ulr_source = 'Short'
AND dom2.valuation_class = f.div_level_join 
AND dom2.year_type = 'UW'
AND f.undwrtr_yr_prd_fy_mnth BETWEEN dom2.start_year_month AND dom2.end_year_month

Upvotes: 0

Views: 3541

Answers (1)

Gordon Linoff
Gordon Linoff

Reputation: 1269883

I think you can fix this (to a close approximation) by using a where clause. It should read:

where (f.undwrtr_yr_prd_fy_mnth BETWEEN dom1.start_year_month AND dom1.end_year_month or
       dom1.valuation_class is null
      ) and
      (f.undwrtr_yr_prd_fy_mnth BETWEEN dom2.start_year_month AND dom2.end_year_month or
       dom2.valuation_class is null
      )

There are some subtle differences between having the condition in the where clause versus the on clause, but they probably will not affect your query.

Upvotes: 1

Related Questions