mezz
mezz

Reputation: 437

HIve join with a where query

I basically want to to a cross join with my store-product master list with the calendar table that has all possible dates. However, i want to filter for a year (365 days) before making the join with the master list.

I am trying the following query -

select * from ( select a.store_id,a.product_id from mez_2018_store_product_lst) a cross join
(select b.day_id,cast(to_date(from_unixtime(unix_timestamp(b.day_date, 'yyyy-MM-dd'))) as b.date from calendar where day_id>=20170101 and day_id<=20180101 ) b

And I keep getting EOF error. Can you guys help ?

Upvotes: 1

Views: 38

Answers (1)

notNull
notNull

Reputation: 31540

Try with below query:

 hive> select * from 
 (select store_id,
    product_id from mez_2018_store_product_lst) a 
 cross join
(select day_id,
    to_date(from_unixtime(unix_timestamp(day_date, 'yyyy-MM-dd')))dt from calendar 
    where day_id>=20170101 and day_id<=20180101 ) b;

Upvotes: 2

Related Questions