2017-06-22 60 views
1

蜂巢版本是0.13,蜂巢表說明如下:插入CSV數據到複雜的蜂巢表

CREATE TABLE temp 
(
customer_id int, 
sales_item array<struct<item_id:int,item_name:string,item_price:decimal(10,2)>>, 
) 
ROW FORMAT DELIMITED 
FIELDS TERMINATED BY ',' 
COLLECTION ITEMS TERMINATED BY '|'; 

我的CSV文件:

10,1|watch|300 

如何插入到蜂巢表...我試過了,輸出如下:

10 [{"item_id":1,"item_name":null,"item_price":null}] 

沒有爲item_name和item_price插入任何值。

回答

0

分隔符的當前文檔存在問題。我稍後會更新它。
它實際上是不領域藏品地圖鍵但嵌套級別1,2和3並且有不被create table語法映射其他級別。

create external table temp 
(
    customer_id  int 
    ,sales_item  array<struct<item_id:int,item_name:string,item_price:decimal(10,2)>> 
) 
row format delimited 
fields terminated by ',' 
map keys terminated by '|' 
; 

select * from temp 
; 

+-------------+------------------------------------------------------+ 
| customer_id |      sales_item      | 
+-------------+------------------------------------------------------+ 
|   10 | [{"item_id":1,"item_name":"watch","item_price":300}] | 
+-------------+------------------------------------------------------+ 
+0

查看更新後的答案 –

+0

謝謝......這個解決方案爲我... –