gpt4 book ai didi

hadoop - hive :尝试映射键和值时出错

转载 作者:行者123 更新时间:2023-12-02 20:31:13 25 4
gpt4 key购买 nike

我有一个这样的查询,我试图将array<struct<key:string,value:array<string>>转换为map<string,array<string>>
查询是

SELECT name, address, location, map(collect_set(k1),collect_set(concat_ws("",v1))) AS key_one
FROM table_a
lateral view inline(key_one) t1 as k1,v1
GROUP BY name, address, location;

我得到的错误是 FAILED: SemanticException [Error 10016]: Line 1:62 Argument type mismatch 'v1': Primitive Type is expected but array<string>" is found

最佳答案

该错误表明您不能将复杂的数据类型(即数组,结构,映射)作为映射键。
这是正确的。键只能是一个值,因此必须是原始值(即String,Int,BigInt)

但是,您的代码尝试将键放置为数组,因此会出现错误。您需要做的是首先分解数组,然后尝试获取键和值以形成映射。

这可能有效。

创建表

create table temp.test_struct (test array<struct<key:string,value:array<string>>>) 

插入值
insert into temp.test_struct 
select array(
NAMED_STRUCT("key", "k1", "value", array("a","b","c")),
NAMED_STRUCT("key", "k2", "value", array("x","y","z"))
) from (select 'a') x

将结构数组转换为映射
select test, map(t1.key, t1.value) map_col
from
temp.test_struct
lateral view inline(test) t1

enter image description here

关于hadoop - hive :尝试映射键和值时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53255520/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com