Hadoop 我的配置单元表具有类型为map的列<;字符串,字符串>;。我想分解地图并将它们转换为列而不是行

Hadoop 我的配置单元表具有类型为map的列<;字符串,字符串>;。我想分解地图并将它们转换为列而不是行,hadoop,hive,Hadoop,Hive,下面是我的配置单元表结构 data_dt string id string records map<string,string> 根据Hive文档,我的地图记录被分解成数据行。我需要以列而不是行的形式分解数据 E.x: 上面的问题会给我答案 abc | k1 | v1 abc | k2 | v2 abc | k3 | v3 zxc | k1 | v1 zxc | k3 | v3

下面是我的配置单元表结构

data_dt                 string
id                      string
records                 map<string,string>
根据Hive文档,我的地图
记录
被分解成数据行。我需要以列而不是行的形式分解数据

E.x: 上面的问题会给我答案

abc | k1 | v1
abc | k2 | v2
abc | k3 | v3
zxc | k1 | v1
zxc | k3 | v3
相反,我需要它如下

id  | k1 | k2 | k3
abc | v1 | v2 | v3
zxc | v3 | /N | v3

我知道explode是一个UDTF,因此它会将结果转储为行而不是列。但是有没有办法以列而不是行的形式获取数据?

您可以这样运行查询:

select id, max(k1) as k1, max(k2) as k2, max(k3) as k3 from (
select id, case when c2 = 'k1' then c3 end as k1,
case when c2 = 'k2' then c3 end as k2,
case when c2 = 'k3' then c3 end as k3
from table_name) q;

记录映射中是否有任意数量的字段?你需要所有这些字段还是一些字段?我需要地图上的所有字段。你有什么解决方案吗?我现在也有同样的要求,在使用R的帖子中这样做。e、 例如,
dcast(tbl,…~key,value.var='val')
@RamGhadiyaram和Clayton一样,我最终使用了R进行后期处理。这个表非常大(大约20亿条记录),所以有一个case语句对我没有帮助。。我在找更有活力的东西。。
select id, max(k1) as k1, max(k2) as k2, max(k3) as k3 from (
select id, case when c2 = 'k1' then c3 end as k1,
case when c2 = 'k2' then c3 end as k2,
case when c2 = 'k3' then c3 end as k3
from table_name) q;