我有一个这样的查询,试图将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
答案 0 :(得分:0)
该错误表明您不能将复杂的数据类型(即数组,结构,映射)作为映射键。 这是正确的。键只能是一个值,因此必须是原始值(即String,Int,BigInt)
但是,您的代码尝试将键放置为数组,因此会出现错误。您需要做的是首先分解数组,然后尝试获取键和值以形成映射。
这可能有效。
创建表格
DELETE TOP 100 from [LocalTable]
插入值
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