hive数组< struct< >>插入显示空

6jygbczu  于 2021-06-01  发布在  Hadoop
关注(0)|答案(1)|浏览(489)

我创建了一个具有struct数组的表temp

create table temp (regionkey smallint, name string, comment string, nations array<struct<n_nationkey:smallint,n_name:string,n_comment:string>>) 
ROW FORMAT DELIMITED 
FIELDS TERMINATED BY '|' 
COLLECTION ITEMS TERMINATED BY ',';

然后我将数据加载到表中

LOAD DATA LOCAL INPATH '/Data Sets/region.csv' INTO TABLE temp;

期望输出什么时候有

select * from temp;

4   EUROPE  Low sale Business Region [{"n_nationkey":22,"n_name":"Ryan","n_comment":"Reference the site"}]

但实际产出是

4   EUROPE  Low sale Business Region    [{"n_nationkey":22,"n_name":null,"n_comment":null},{"n_nationkey":null,"n_name":null,"n_comment":null},{"n_nationkey":null,"n_name":null,"n_comment":null}]

数据文件

4|EUROPE|Low sale Business Region for Training4Exam.com|7,Bulgaria,Reference 
4|EUROPE|Low sale Business Region for HadoopExam.com|19,Belgium,Reference site 
4|EUROPE|Low sale Business Region for Training4Exam.com|22,Ryan,Reference site

这是我第一次使用数组和结构进行考试,我对此一无所知。如有任何帮助,我们将不胜感激。谢谢

dxxyhpgq

dxxyhpgq1#

map keys terminated by ',' ```
create external table temp
(
regionkey smallint
,name string
,comment string
,nations array<struct<n_nationkey:smallint,n_name:string,n_comment:string>>
)
row format delimited
fields terminated by '|'
map keys terminated by ','
;

select * from temp
;

+-----------+--------+------------------------------------------------+-----------------------------------------------------------------------+
| regionkey | name | comment | nations |
+-----------+--------+------------------------------------------------+-----------------------------------------------------------------------+
| 4 | EUROPE | Low sale Business Region for Training4Exam.com | [{"n_nationkey":7,"n_name":"Bulgaria","n_comment":"Reference "}] |
| 4 | EUROPE | Low sale Business Region for HadoopExam.com | [{"n_nationkey":19,"n_name":"Belgium","n_comment":"Reference site "}] |
| 4 | EUROPE | Low sale Business Region for Training4Exam.com | [{"n_nationkey":22,"n_name":"Ryan","n_comment":"Reference site"}] |
+-----------+--------+------------------------------------------------+-----------------------------------------------------------------------+


## 仅供参考

要向后兼容,请将前3个分隔符初始化为表属性中的给定值。
分隔符的默认数目是8;
如果只设置了hive.serialization.extend.nesting.levels,则分隔符的数目将扩展到24;
如果设置了hive.serialization.extend.additional.nesting.levels,则分隔符的数目将扩展到154。
@param tableproperties table properties提取用户提供的分隔符
https://github.com/apache/hive/blob/master/serde/src/java/org/apache/hadoop/hive/serde2/lazy/lazyserdeparameters.java

相关问题