Insert data into Hive table using lookup table

507 Views Asked by At

Could someone help me in this scenario?

How to insert data into a Hive table by looking up values from other Hive table?

My input_source table is like below:

date    key  lines  type
29-May  1     A     A16
29-May  2     B     D44
29-May  3     C     K90
29-May  4     A     L90
29-May  5     A     J76
29-May  6     B     Y78

I have detailed description of each of the types above. For example:

A and A16 is "Excellet"
B and D44 is "Average"
A and L90 is "Good"
B and Y78 is "Fair"

and so on..

During I insert the data into result table, I need to read the lines and type and insert the description in the final table as below:

date    key   desc
29-May  1     Excellent
29-May  2     Average
29-May  3     Not bad
29-may  4     Good
29-May  5     Fine
29-may  6     Fair

Could you please advice to achieve this?

1

There are 1 best solutions below

1
On

Use Join. Here is what is probably needed.

insert overwrite table target_table
select date,key,descrip
from 
(
select a.date,a.key,a.lines, a.type,b.descrip from 
input_source a 
join 
description_table b 
on a.lines = b.lines and a.type = b.type
)
t;

Let me know if this helps!