一.SerDe
SerDe:Serializer and Deserializer 序列化及反序列化,构建在数据存储和执行引擎之间,对两者实现解耦。
Hive通过ROW FORMAT DELIMITED 以及SERDE进行内容的读写。
样板:
row format
:DELIMITED
[FIELDS TERMIINATED BY char [ESCAPED BY char]
[COLLECTION ITEMS TERMINATED BY char]
[MAP KEYS TERMINATED BY char]
[LINES TERMINATED BY char]
:SERDE serde_name [WITH SERDEPROPERTIES (property_name=property_value,property_name=property_value...)]
案例1:
create table zhen(id int, name string,age int)
row format delimited fields terminated by ',' collection items terninated by ',' map keys terminated by ':' lines terminated by '\n' ;
案例2:
create table zhen(id int, name string,age int)
row format serde 'org.apache.hadoop.hive.serde2.RegexSerDe' with serdeproperties("input.regex" = "([^ ])([^ ])([^ ])") // 正则匹配
stored as textfile;
备注:lines 默认按照换行拆分!
二.Beeline
格式化数据表数据,Beeline要和HiveServer2配合使用。服务端启动hiveserver2,客户端通过beeline两种方式连接hive
1.beeline -u jdbc:hive2://localhost:10000/default -n root
2.1.beeline
2.2 !connect jebc:hive2:/localhost:10000/defalut;auth-noSasl root 123