【问题标题】:is it possible to update complex data type in hive? e.x: map, array, struct是否可以在 hive 中更新复杂的数据类型?例如:映射、数组、结构
【发布时间】: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]个元素?

【问题讨论】:

    标签: hive hiveql


    【解决方案1】:

    使用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
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-09-07
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多