【问题标题】:Hive Reading only one json rowHive 只读取一个 json 行
【发布时间】:2022-01-10 00:12:10
【问题描述】:

我有一个这样的json

[{"event": "1", "meta": {"name":"Kumar","":"28"}}, {"event": "2", "meta": {"name":"Harsh","":"27"}}]

我删除了方括号,因为在 hive 中它给出了错误 org.apache.hadoop.hive.serde2.SerDeException: java.io.IOException: Start token not found where expected

{"event": "1", "meta": {"name":"Kumar","":"28"}}, {"event": "2", "meta": {"name":"Harsh","":"27"}}

我正在像这样创建我的表

create external table record_two(event string,meta struct<name:string,age:string>)
ROW FORMAT SERDE 'org.apache.hcatalog.data.JsonSerDe'
LOCATION '/test/event_two/'; 

表已创建,但当我运行 select 时它只返回一条记录

【问题讨论】:

    标签: json hive hiveql create-table hiveddl


    【解决方案1】:

    记录应该在数据文件中的单独行中。

    {"event": "1", "meta": {"name":"Kumar","age":"28"}}
    {"event": "2", "meta": {"name":"Harsh","age":"27"}}
    

    记录之间没有逗号,只有换行符。

    【讨论】:

    • 就像只有来自 sourec 的 thi 一样,是否有任何方法可以读取单行或使用额外的大括号
    • @KumarHarsh- 输入原始数组,将表定义为complex_col array&lt;struct&lt;event:string,meta:struct&lt;name:string,age:string&gt;&gt;&gt;,使用 ROW FORMAT SERDE 'org.openx.data.jsonserde.JsonSerDe' 在此处查看示例:github.com/rcongiu/Hive-JSON-Serde 但在这种情况下,数组将不会爆炸。 Serde 生成的行数不能超过文件中的行数......
    猜你喜欢
    • 1970-01-01
    • 2012-11-07
    • 1970-01-01
    • 2019-12-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多