Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/meteor/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Hive 在配置单元中从多行透视到多列_Hive - Fatal编程技术网

Hive 在配置单元中从多行透视到多列

Hive 在配置单元中从多行透视到多列,hive,Hive,我有一张蜂巢桌,如下所示 (id:int, vals: Map<String, int> , type: string) id, vals, type 1, {"foo": 1}, "a" 1, {"foo": 2}, "b" 2, {"foo": 3}, "a" 2, {"foo": 1}, "b" 如果缺少任何“类型”,它可以为空?记住map列的简单方法是自连接 select ta.id,ta.vals,tb.vals from (select * from tbl where

我有一张蜂巢桌,如下所示

(id:int, vals: Map<String, int> , type: string)
id, vals, type
1, {"foo": 1}, "a"
1, {"foo": 2}, "b"
2, {"foo": 3}, "a"
2, {"foo": 1}, "b"

如果缺少任何“类型”,它可以为空?

记住
map
列的简单方法是
自连接

select ta.id,ta.vals,tb.vals
from (select * from tbl where type = 'a') ta 
full join (select * from tbl where type = 'b') tb on ta.id = tb.id 
您可以使用条件聚合来解决如下问题。但是,在
映射
列上执行此操作将产生错误

select id
      ,max(case when type = 'a' then vals end) as type_a_vals
      ,max(case when type = 'b' then vals end) as type_a_vals
from tbl
group by id
select id
      ,max(case when type = 'a' then vals end) as type_a_vals
      ,max(case when type = 'b' then vals end) as type_a_vals
from tbl
group by id