溫馨提示×

hive數組怎樣實現元素刪除

小樊
121
2024-12-20 18:35:03
欄目: 大數據

Hive中的數組類型可以通過ARRAYSTRUCT數據類型來表示

  1. 使用ARRAYSTRUCT數據類型創建表:
CREATE TABLE example_table (
    id INT,
    item_list ARRAY<STRING>,
    item_struct STRUCT<name STRING, quantity INT>
);
  1. 插入數據:
INSERT INTO example_table (id, item_list, item_struct)
VALUES (1, ARRAY("apple", "banana", "orange"), STRUCT("apple", 2));
  1. 使用LATERAL VIEWEXPLODE函數將數組轉換為行,然后使用FILTER子句刪除不需要的元素:
SELECT t.id, item
FROM example_table t
LATERAL VIEW INLINE(t.item_list) items AS item
WHERE item != 'banana';

這將返回以下結果:

id | item
---------
1  | apple
1  | orange

在這個例子中,我們使用LATERAL VIEW INLINE函數將item_list數組轉換為行,然后使用FILTER子句刪除不需要的元素(“banana”)。

0
亚洲午夜精品一区二区_中文无码日韩欧免_久久香蕉精品视频_欧美主播一区二区三区美女