[Hive_add_10] Hive 的 serde (序列化 & 反序列化) 操作


0. 说明

  serde 是序列化和反序列化 serialize & deserialize

  是将文件中的字段映射成 Hive 中的列


1. 验证

  1.1 openCSVSerde

  CSV 为逗号分隔的文件

create table serde_csv (id int, name string , age int)
row format serde 'org.apache.hadoop.hive.serde2.OpenCSVSerde' 
stored as textfile;

create table serde_csv2 (id int, name string , age int)
row format delimited
fields terminated by ',' 
stored as textfile;

  1.2 jsonSerde

  将 json 数据映射成列数据

  1. 准备 1.json 和 json-serde

  2. 部署 json-serde
  将 json-serde-1.3.8-jar-with-dependencies.jar 放置在 /soft/hive/lib 下并重启 Hive

  3. 创建表并指定表 serde   //以反引号作为解析字段``

create table json(`_location` string,`_ip` string,`_action` string, `_uid` string, `_timestamp` string) 
ROW FORMAT SERDE 'org.openx.data.jsonserde.JsonSerDe'
stored as textfile;

  4. 加载数据

load data local inpath '/home/centos/files/1.json' into table json;

  5. 查询验证

select * from json;


原文地址:https://www.cnblogs.com/share23/p/10260507.html