首页 > 解决方案 > 使用查找表将数据插入 Hive 表

问题描述

有人可以在这种情况下帮助我吗?

如何通过从其他 Hive 表中查找值来将数据插入 Hive 表?

我的 input_source 表如下所示:

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

我对上述每种类型都有详细的描述。例如:

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

等等..

在将数据插入结果表期间,我需要读取行并在最终表中键入并插入描述,如下所示:

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

你能建议实现这一目标吗?

标签: hadoophivehive-query

解决方案


使用加入。这可能是需要的。

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;

让我知道这是否有帮助!


推荐阅读