配置单元中的json文件加载跳过第1行

h7appiyu  于 2021-05-29  发布在  Hadoop
关注(0)|答案(1)|浏览(308)

我正在尝试使用本机函数在配置单元中使用一个json数组文件,当它加载到配置单元中时,第一行被转换为null,第一行数据丢失。请告知我做了什么不正确?
数据:

[{"id":1,"first_name":"Alexandrina","email":"abalding0@goo.ne.jp","date":"9/11/2016","country":"Nigeria"},
{"id":2,"first_name":"Craggie","email":"ctremain1@photobucket.com","date":"12/7/2016","country":"China"},
{"id":3,"first_name":"Allie","email":"adearan2@ycombinator.com","date":"10/31/2016","country":"Russia"},
{"id":30,"first_name":"Vinson","email":"vplumbleyt@hubpages.com","date":"5/16/2016","country":"Saint Kitts and Nevis"}]

Hive功能:

CREATE TABLE format.json_table (json string);
LOAD DATA INPATH  '/user/cloudera/JSON/MOCK_DATA.json' INTO TABLE json_table;

当我询问时:

select get_json_object(json_table.json, '$.id') as id,
get_json_object(json_table.json, '$.first_name') as name,
get_json_object(json_table.json, '$.email') as email,
get_json_object(json_table.json, '$.date') as date,
get_json_object(json_table.json, '$.country') as country from json_table;

它回来了

OK
id  name    email   date    country
NULL    NULL    NULL    NULL    NULL
2   Craggie ctremain1@photobucket.com   12/7/2016   China
3   Allie   adearan2@ycombinator.com    10/31/2016  Russia
4   Poul    psondland3@mlb.com  9/11/2016   Nigeria
5   Vinson  vplumbleyt@hubpages.com 5/16/2016   Saint Kitts and Nevis
o4tp2gmn

o4tp2gmn1#

json-serde处理单行文档。
给定您的数据,每一行本身就是一个有效的json文档都会被适当地读取,而每一行都不会使json解析器失败,从而导致返回空值。

相关问题