Hive学习笔记——SerDe
SerDe 是Serializer 和 Deserializer 的简称,它提供了Hive和各种数据格式交互的方式。
Amazon的Athena可以理解是Amazon对标hive的一款产品,其中对SerDe的介绍如下
https://docs.aws.amazon.com/zh_cn/athena/latest/ug/serde-about.html
对于Hive中经常使用的SerDe如下,参考了
Hive_10. Hive中常用的 SerDe 和 当前社区的状态
1.LazySimpleSerDe,用来处理文本格式文件:TEXTFILE
https://github.com/apache/hive/blob/master/serde/src/java/org/apache/hadoop/hive/serde2/lazy/LazySimpleSerDe.java
2.RegexSerDe,可以使用java正则表达式来处理文本格式文件:TEXTFILE
https://github.com/apache/hive/blob/master/serde/src/java/org/apache/hadoop/hive/serde2/RegexSerDe.java
3.JSONSerDe,可以使用它来处理json格式的文本文件:TEXTFILE
https://github.com/rcongiu/Hive-JSON-Serde/blob/master/json-serde/src/main/java/org/openx/data/jsonserde/JsonSerDe.java
第三方的jar包,下载连接
http://www.congiu.net/hive-json-serde/1.3.8/hdp23/json-serde-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
4.OpenCSVSerDe,可以使用它来处理csv格式的文本文件:TEXTFILE
https://github.com/apache/hive/blob/master/serde/src/java/org/apache/hadoop/hive/serde2/OpenCSVSerde.java
5.ParquetHiveSerDe,可以使用它来处理Parquet格式的文件:PARQUET
https://github.com/apache/hive/blob/master/ql/src/java/org/apache/hadoop/hive/ql/io/parquet/serde/ParquetHiveSerDe.java
6.AvroSerDe,可以使用它来处理Avro格式数据的serde:AVRO
https://github.com/apache/hive/blob/master/serde/src/java/org/apache/hadoop/hive/serde2/avro/AvroSerDe.java
7.HBaseSerDe,可以使用它来集成Hive和Hbase
https://github.com/apache/hive/blob/master/hbase-handler/src/java/org/apache/hadoop/hive/hbase/HBaseSerDe.java
8.EsSerDe,可以使用它来集成Hive和Es
https://github.com/elastic/elasticsearch-hadoop/blob/master/hive/src/main/java/org/elasticsearch/hadoop/hive/EsSerDe.java
9.ThriftDeserializer,可以使用它来集成thrift和hive
https://github.com/apache/hive/blob/master/serde/src/java/org/apache/hadoop/hive/serde2/thrift/ThriftDeserializer.java
10.MySQLSerDe
https://cwiki.apache.org/confluence/display/Hive/JDBC+Storage+Handler
使用hive查询mysql需要注意调整分区参数,否则可能会导致数据重复或者连接过多,比如
CREATE EXTERNAL TABLE IF NOT EXISTS `xx.xx`( `a` int COMMENT 'from deserializer', `b` string COMMENT 'from deserializer', `c` int COMMENT 'from deserializer' ) STORED BY 'org.apache.hive.storage.jdbc.JdbcStorageHandler' TBLPROPERTIES ( "hive.sql.database.type" = "MYSQL", "hive.sql.jdbc.driver" = "com.mysql.jdbc.Driver", "hive.sql.jdbc.url" = "jdbc:mysql://xxx:3306/xx_db", "hive.sql.dbcp.username" = "xx_username", "hive.sql.dbcp.password" = "xx_pws", "hive.sql.table" = "xx_table", "hive.sql.dbcp.maxActive" = "1", "hive.sql.query"="SELECT a,b,c FROM xx_table" )
11.MongoSerde
https://github.com/mongodb/mongo-hadoop/ https://blog.csdn.net/zz60708320/article/details/102722361
本文只发表于博客园和tonglin0325的博客,作者:tonglin0325,转载请注明原文链接:https://www.cnblogs.com/tonglin0325/p/13993159.html