HIVE json存储-非法数据处理

存储

1、将json数据以string 方式存储在hive 中,然后比如使用LATERAL VIEW json_tuple的方法,获取所需要的列名,或者 get_json_object(json,’$.id’) 的方式获取数据。
2、底层用json的方式存储
下载Jar
使用之前先下载jar:
http://www.congiu.net/hive-json-serde/
如果要想在Hive中使用JsonSerde,需要把jar添加到hive类路径中:
add jar json-serde-1.3.7-jar-with-dependencies.ja

create EXTERNAL table databases.temp_tb(
v string,
algo  string,
rList array<struct<rtype:string,ctype:string,num:string,cid:string,cause:string>> )
partitioned by(
dt string,
)
ROW FORMAT SERDE 'org.openx.data.jsonserde.JsonSerDe'
STORED AS TEXTFILE
;

alter table databases.temp_tbadd partition (dt='${dt}'') location '/data_dir/'

json存储问题1 如果是非法数据就会报错

可以增加配置用以跳过错误数据,运行查询不会报错,非法数据记录将变为NULL。
ALTER TABLE tabled*** SET SERDEPROPERTIES ( "ignore.malformed.json" = "true");

json存储问题2 json数据中包含hive关键字时,导入的数据报错

此时 SerDe可以使用SerDe属性将hive列映射到名称不同的属性

create EXTERNAL table databases.temp_tb(
ids_alias string,
algo  string,
rList array<struct<rtype:string,ctype:string,num:string,cid:string,cause:string>> )
partitioned by(
dt string,
)
ROW FORMAT SERDE 'org.openx.data.jsonserde.JsonSerDe'
WITH SERDEPROPERTIES ("mapping.ids_alias"="ids")
STORED AS TEXTFILE
;
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值