Hive - 如何从列表类型的 table 中读取列

Hive - How to read a column from a table which is of type list

我有一个名为 customer 的 Hive table,它有一个名为 cust_id 的列表类型的列,具有以下值: cust_id

[123,234,456,567]

[345,457,67]    

[89,23,34]    

现在我想在我的 select 查询中只读取这个特定的列 cust_id,它可以给出所有这些列表值作为此列 cust_id 的以下单独值:

cust_id

123

234

456

567

345

457

67

89

23

34

基本上我想从这个 table 中获取 cust_id 的所有值作为一列,以便在我的其他查询的 where exists 或 where in 子句中使用这些值。 对此的解决方案将不胜感激。

据我所知,这就是您要从配置单元手册中查找的内容..

Lateral view is used in conjunction with user-defined table generating functions such as explode(). As mentioned in Built-in Table-Generating Functions, a UDTF generates zero or more output rows for each input row.

例如

SELECT cust_id
FROM mytable LATERAL VIEW explode(cust_id) mytab AS cust_id;

完整示例:

drop table customer_tab;
create table customer_tab ( cust_id array<String>);

INSERT INTO table customer_tab select array('123','234','456','567');

INSERT INTO table customer_tab select array('345','457','67');

INSERT INTO table customer_tab select array('89','23','34');

select * from customer_tab;
--      customer_tab.cust_id
--      ["123","234","456","567"]
--      ["345","457","67"]
--      ["89","23","34"]

SELECT mytab.cust_id
FROM customer_tab LATERAL VIEW explode(cust_id) mytab AS cust_id;


mytab.cust_id
123
234
456
567
345
457
67
89
23
34