【发布时间】:2018-05-17 15:30:27
【问题描述】:
我想知道: 是否可以在 hive 中更新复杂的数据类型?例如:映射、数组、结构 使用 ACID 表和 UPDATE 语法?
例如我们有一张桌子:
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"));
所以我们的数据在表中:
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;
更新数据:
select * from complex_nested_types_update_array_map order by person_id;
1 {"John":["+44801123311","+120342234","+230342234","+3303422434"]}
2 {"AAron":["edited","edited","+230342234","+3303422434"]}
但是我们可以只更新[2],还是只更新数组的[3]个元素?
【问题讨论】: