从非嵌套的json数据文件创建hive表会将输出显示为null

时间:2017-11-02 09:28:29

标签: json hadoop hive

我正在尝试从hdfs中的json文件创建一个Hive表(“desiredtable”)。
以下是我遵循的步骤:

最初我已将hive-serdes-1.0-SNAPSHOT.jar复制到hive/lib文件夹中。

1.  add jar /usr/local/hive/lib/hive-serdes-1.0-SNAPSHOT.jar;
2.  create external table sample_data (reviewerID string , reviewText string )
    row format serde 'com.cloudera.hive.serde.JsonSerDe'
    location '/dataset';
3.  create table desiredtable as select * from sample_data;
4.  select * from desiredtable ;

但是在执行第4步时,它会返回空值,如下图[1]所示 Json数据的格式如下:

{
    "reviewerID": "A00000262KYZUE4J55XGL",
    "asin": "B003UYU16G",
    "reviewerName": "Steven N Elich",
    "helpful": [0, 0],
    "reviewText": "It is and does exactly what the description said it would be and would do. Couldn't be happier with it.",
    "overall": 5.0,
    "summary": "Does what it's supposed to do",
    "unixReviewTime": 1353456000,
    "reviewTime": "11 21, 2012"
}

{
    "reviewerID": "A000008615DZQRRI946FO",
    "asin": "B005FYPK9C",
    "reviewerName": "mj waldon",
    "helpful": [0, 0],
    "reviewText": "I was sketchy at first about these but once you wear them for a couple hours they break in they fit good on my board an have little wear from skating in them. They are a little heavy but won't get eaten up as bad by your grip tape like poser dc shoes.",
    "overall": 5.0,
    "summary": "great buy",
    "unixReviewTime": 1357603200,
    "reviewTime": "01 8, 2013"
}

请指导我犯下的错误是什么?

1 个答案:

答案 0 :(得分:1)

这是一个区分大小写的问题。 SQL列不区分大小写,但JSON键不区分。

您需要在JSON密钥中使用小写。

Old Hive版本不支持JSON Key中的混合大小写。

https://github.com/rcongiu/Hive-JSON-Serde/issues/4