配置Hive 支持 JSON 存储


1、说明

hive默认使用分隔符如空格,分号,"|",制表符\t来格式化数据记录,对于复杂数据类型如json,nginx日志等,就没有办法拆分了,这时候需要更加强大的SerDe来处理复杂数据,
如使用JsonSerDe或者使用正则表达式RegSerDe来处理。


2、下载jar包

json-serde-1.3.8-jar-with-dependencies.jar:
http://www.congiu.net/hive-json-serde/1.3.8/hdp23/json-serde-1.3.8-jar-with-dependencies.jar


json-udf-1.3.8-jar-with-dependencies.jar:
http://www.congiu.net/hive-json-serde/1.3.8/hdp23/json-udf-1.3.8-jar-with-dependencies.jar


3、配置hive

1、将下载的json-serde-1.3.8-jar-with-dependencies.jar包放到hive的lib目录下

2、配置hive-site.xml文件,添加jar包的声明,永久注册
    <property>
        <name>hive.aux.jars.path</name>
        <value>file:///soft/hive/lib/json-serde-1.3.8-jar-with-dependencies.jar</value>
    </property>

3、设置不压缩存储
    <property>
        <name>hive.exec.compress.output</name>
        <value>false</value>
    </property>


4、建表语句语法

hive> create table test(id int , name string) ROW FORMAT SERDE 'org.openx.data.jsonserde.JsonSerDe' STORED AS TEXTFILE;
posted @ 2019-12-02 10:33  米兰的小铁將  阅读(847)  评论(0编辑  收藏  举报