如何从数组以及HIVE中的其他列提取值

时间:2018-10-06 23:15:14

标签: hive hiveql

  

嗨,   我有一个包含以下列的配置单元表   partid字符串,表中存储字符串和位置数组,值按此顺序保存

part123, store123, location 
[{"position":1,"price":124.0,"card_pos":"External","clicked":0},
 {"position":2,"price":94.78,"card_pos":"Cbox","clicked":0},
 {"position":3,"price":94.77,"card_pos":"External","clicked":0}] 
>

我可以在一行中看到arry的值,我也想 以这种方式查看partid,store和location值。 >

+---------+-----+----------+--------+-----------+----------+  
partid |store   | position | price  | card_pos  | clicked  |  
+---------+-----+----------+--------+-----------+----------+  
part123|store123| 1        | 124.0    | External | 0       |     
part123|store123| 2        | 94.78    | Cbox     | 0       |    
part123|store123| 3        | 94.77    | External | 0       |  
+---------+-----+----------+----------+----------+---------+  

> 到目前为止,我只能通过以这种方式使用内联函数来查看数组值。

select inline(location) as (position, price, card_pos, clicked) from table;  

>+---------+--------+-----------+----------+  
| position | price  | card_pos  | clicked  |  
+----------+--------+-----------+----------+  
| 1        | 124.0    | External | 0       |   
| 2        | 94.78    | Cbox     | 0       |  
| 3        | 94.77    | External | 0       |   
+----------+----------+----------+---------+  

>

1 个答案:

答案 0 :(得分:1)

mock-restlateral view结合使用,然后选择其他列。

inline

编辑:如果OP处理select partid,store,t.position,t.price,t.card_pos,t.clicked from table lateral view inline(location) t as position, price, card_pos, clicked 列为array时的情况,请使用null选项。

lateral view outer