前言
本文隶属于专栏《1000个问题搞定大数据技术体系》,该专栏为笔者原创,引用请注明来源,不足和错误之处请在评论区帮忙指出,谢谢!
本专栏目录结构和参考文献请见1000个问题搞定大数据技术体系
正文
通过 MultiDelimitSerDe 解决多字符分割场景
- 1、创建表
create table t1 (id String, name string)
row format SerDe 'org.apache.hadoop.hive.contrib.SerDe2.MultiDelimitSerDe'
WITH SERDEPROPERTIES ("field.delim"="##");
- 2、准备数据 t1.txt
1##xiaoming
2##xiaowang
3##xiaozhang
- 3、加载数据
load data local inpath '/home/hadoop/t1.txt' into table t1;
- 4、查询数据
0: jdbc:hive2://node1:10000> select * from t1;
+--------+------------+--+
| t1.id | t1.name |
+--------+------------+--+
| 1 | xiaoming |
| 2 | xiaowang |
| 3 | xiaozhang |
+--------+------------+--+
通过 RegexSerDe 解决多字符分割场景
- 1、创建表
create table t2(id int, name string)
row format SerDe 'org.apache.hadoop.hive.SerDe2.RegexSerDe'
WITH SERDEPROPERTIES ("input.regex" = "^(.*)\\#\\#(.*)$");
- 2、准备数据 t1.txt
1##xiaoming
2##xiaowang
3##xiaozhang
- 3、加载数据
load data local inpath '/home/hadoop/t1.txt' into table t2;
- 4、查询数据
0: jdbc:hive2://node1:10000> select * from t2;
+--------+------------+--+
| t2.id | t2.name |
+--------+------------+--+
| 1 | xiaoming |
| 2 | xiaowang |
| 3 | xiaozhang |
+--------+------------+--+