多字节分隔符

一、简介

      在hive中默认只支持单字节分隔符,不支持多字节(超过一个字节)分割符的。

      单字节:|   .   :   \t

      多字节:||    ::     ..

      create table test01(id int,name string) row format delimited fields terminated by '::';

      load data local inpath '/home/hadoop/apps/test01' into table test01;

      上面导入数据之后,是不行的。

二、分割方式

1、将多字节换成单字节

      ::à:

      这样做有风险的

      1::Toy Story (1995)::Animation|Children's|Comedy

      1:Toy Story (1995):Animation|Children's|Comedy

      一定对数据足够了解,知道里面的数据的分隔都是利用相同的多字节来的。

2、修改源代码

      将hive源代码修改为支持多字节的,这样做的话,以后所有的数据都得是多字节切分的,遇到单字节切分的还需在改过来,所以不建议用这种方法。

3、自定义字段分割符(正则表达式)

create table test02(id int,name string)

row format serde 'org.apache.hadoop.hive.serde2.RegexSerDe'

with serdeproperties('input.regex'='(.*)::(.*)','output.format.string'='%1$s %2$s') stored as textfile;

load data local inpath '/home/hadoop/apps/test01' into table test02;

 

posted @ 2019-06-16 23:26  快乐的张小凡  阅读(587)  评论(0编辑  收藏  举报