在Hive中,默认情况下只支持单字节的分隔符,如果我们需要用多字节作为分隔符,就需要使用正则序列化。
- 建表
hive> create table if not exists test_regex(
> id string,
> name string,
> age int
> )
> row format serde 'org.apache.hadoop.hive.serde2.RegexSerDe'
> with serdeproperties(
> 'input.regex'='(.*)\\|\\|(.*)\\|\\|(.*)', #原始数据的正则
> 'output.format.string'='%1$s %2$s %3$s' #输出数据的格式
> )
> stored as textfile
> ;
- 创建数据文件
[root@hadoop01 test_data]# pwd
/usr/local/wyh/test_data
[root@hadoop01 test_data]# cat test_regex.txt
001||Jim||19
004||Alice||21
007||Bob||16
- 导入数据 </