我创建了一个具有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
这是我第一次使用数组和结构进行考试,我对此一无所知。如有任何帮助,我们将不胜感激。谢谢
1条答案
按热度按时间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"}] |
+-----------+--------+------------------------------------------------+-----------------------------------------------------------------------+