【问题标题】:Ingesting JSON data into Hive using JSON-SERDE使用 JSON-SERDE 将 JSON 数据摄取到 Hive
【发布时间】:2018-08-03 23:48:16
【问题描述】:

我正在尝试使用 JSON-SERDE 将以下 JSON 数据摄取到 Hive 中,但出现错误。首先 - 这个 JSON 数据有效吗?如果是,如何创建agentId的这一列表,值为123456-123456。

{"agentId":{"string":"123456-123456"}}

CREATE EXTERNAL TABLE testingjson(
    agentId map <string>
)
ROW FORMAT SERDE 'org.apache.hive.hcatalog.data.JsonSerDe'
STORED AS TEXTFILE
LOCATION '/.../json_table';

编译语句时出错:FAILED: ParseException line 4:20 不匹配的输入“>”期望,在地图类型中的“字符串”附近

【问题讨论】:

    标签: json hive


    【解决方案1】:

    是的,json 是有效的。

    试试下面的ddl和

    如果你想要值 123456-123456 然后使用 select agentid['string'] from testingjson;

    hive>CREATE EXTERNAL TABLE testingjson(
    agentId map <string,string>
    )
    ROW FORMAT SERDE 'org.apache.hive.hcatalog.data.JsonSerDe'
    STORED AS TEXTFILE 
    LOCATION '/.../json_table';
    
    hive> select * from testingjson;
    +-----------------------------+--+
    |     testingjson.agentid     |
    +-----------------------------+--+
    | {"string":"123456-123456"}  |
    +-----------------------------+--+
    hiv> select agentid['string'] from testingjson;
    +----------------+--+
    |      _c0       |
    +----------------+--+
    | 123456-123456  |
    +----------------+--+
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-09-01
      • 2015-10-02
      • 2016-02-28
      • 1970-01-01
      • 2019-10-03
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多