Hive版本为0.13,Hive表描述如下:
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
如何插入hive表...我试过,我的输出如下:
10 [{"item_id":1,"item_name":null,"item_price":null}]
不为item_name和item_price插入任何值。
答案 0 :(得分: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}] |
+-------------+------------------------------------------------------+