是否可以更新配置单元中的复杂数据类型? e.x:map,array,struct

时间:2018-05-17 15:30:27

标签: hive hiveql

我想知道: 是否可以更新配置单元中的复杂数据类型? e.x:map,array,struct 使用ACID表和UPDATE语法?

e.g。我们有一张桌子:

GET /Services/{Instance SID}/Users/{User SID}/Channels

并插入数据:

CREATE TABLE complex_nested_types_update_array_map (
person_id int,
person_info MAP <STRING, ARRAY <STRING>>)
CLUSTERED BY (person_id) INTO 2 BUCKETS STORED AS ORC TBLPROPERTIES ("transactional"="true"); 

所以我们将数据放在表格中:

insert into table complex_nested_types_update_array_map 
SELECT 1, map('John', array("+44801123311", "+120342234", "+230342234", "+3303422434"));
insert into table complex_nested_types_update_array_map 
SELECT 2, map('Tomas', array("+380342234", "+230342234", "+230342234", "+530342234"));

是否可以在不覆盖整行的情况下更新特定的数组元素?

e.g:

select * from complex_nested_types_update_array_map order by person_id;

1   {"John":["+44801123311","+120342234","+230342234","+3303422434"]}
2   {"Tomas":["+380342234","+230342234","+230342234","+530342234"]}

更新数据:

UPDATE complex_nested_types_update_array_map SET
person_info = map('AAron', array("edited", "edited", "+230342234", "+3303422434"))
WHERE person_id = 2;

但是我们只能更新[2],或只更新数组的[3]元素吗?

1 个答案:

答案 0 :(得分:0)

使用insert overwrite选项。

insert overwrite table complex_nested_types_update_array_map 
select person_id,map('AAron', array("edited", "edited", "+230342234", "+3303422434")) as person_info
from complex_nested_types_update_array_map 
WHERE person_id = 2
union all
select person_id,person_info
from complex_nested_types_update_array_map 
where person_id<>2