Hive 创建表:解析 json 文件时解析错误缺少“>”

Posted

技术标签:

【中文标题】Hive 创建表:解析 json 文件时解析错误缺少“>”【英文标题】:Hive create table : parse error missing ">" while parsing json file 【发布时间】:2014-08-24 23:45:28 【问题描述】:

我在创建 hive 表时遇到以下异常。谁能指出我的错误? 示例输入:"user":"userlocation":"Bolton, UK","id":14141159,"name":"Chris Beckett","screenname":"ChrisBeckett","geoenabled":true," tweetmessage":"vCOps 人 - 高级版 == 5 个 VM?我知道 Std 有 UI 和分析 VM,但其余的使用什么?Hyperic 等?#vmware #vcops","createddate":"2013-06-20T12: 08:46","地理位置":null

enter code here

   CREATE EXTERNAL TABLE IF NOT EXISTS twitter(
   users map<string,string,string,string,string>,
   message string,
    createddate string,
    geolocation string
  )
    ROW FORMAT SERDE 'org.apache.hadoop.hive.contrib.serde2.JsonSerde'
  LOCATION ' /user/root/hadoop_tests/sample_twitter_data.txt';

    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.apache.hadoop.util.RunJar.main(RunJar.java:212)

FAILED: ParseException line 2:23 missing > at ',' near 'string' in column type 第 2:30 行无法识别列类型中 ',' 'string' ',' 附近的输入

【问题讨论】:

【参考方案1】:

也许你应该使用 Struct 而不是 Map.Below:

CREATE EXTERNAL TABLE IF NOT EXISTS twitter(
   users  struct<userlocation:string,id:string,name:string,screenname:string,geoenabled:string>,
   message string,
   createddate string,
   geolocation string
)
ROW FORMAT SERDE 'org.apache.hadoop.hive.contrib.serde2.JsonSerde'
LOCATION '/user/root/hadoop_tests/';  

【讨论】:

是的,意识到我应该使用结构。我进行了更改,但由于某种原因,数据被加载为 Null。只有 createddate 字段被选中。所有其他列数据为空。任何想法

以上是关于Hive 创建表:解析 json 文件时解析错误缺少“>”的主要内容,如果未能解决你的问题,请参考以下文章

hive 非正确json格式字段造成查询错误

如何为 Hive 创建架构以使用 SerDe 解析深度嵌套的 json(Azure Application Insights 输出)?

Hive:解析 JSON

Hive解析Json数据

hive 存储,解析,处理json数据

使用 Java 从 BigQuery 到 BigQuery 表的表复制中的 JSON 解析错误