原文:http://bbs.chinahadoop.cn/thread-5343-1-1.html
----------------------------------------------------------------------------------
本文的目的是hive读取cvs文件,忽略字段中‘\,’,最终还是以','来分割文本
 cvs格式是以逗号','隔开的文件格式,文本中可能在字段里又包含了逗号转义符号‘\,’
 文件格式举例:
 1,2,5,(hah\,ahojg)
 如果用hive自带的分隔符建表:
 create table IF NOT EXISTS test_table(p_id INT,tm INT,idate INT,url STRING)
 partitioned by (dt string)
 row format delimited fields terminated by ','   或者为 '\,' 
 STORED AS INPUTFORMAT
 'com.hadoop.mapred.DeprecatedLzoTextInputFormat'  
 OUTPUTFORMAT  
 'org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat' 
 location '/hdfs/data/incoming';
 结果都会被分为:1 2 5 (hah\ ahojg)
 因为hive只识别一个字符的分隔符,所以需要我们编写自己的input/output format
 下面这段代码是网上截取的,将多个分隔符换成hive自带的\001
 想要忽略‘\,’的目的,建红色的代码修改如下即可:
 //先将‘\,’换成'@' ,处理完逗号分隔符,再将'@' 换成 '\,'
 String repalceString_01 = value.toString().replace("\\,", "@");
 String repalceString_02 = repalceString_01.replace(",", "\001");
 String strReplace = repalceString_02.replace("@", "\\,");
 ------------------------------------------------------------------------------------------------------
 步骤:myeclipse中建立java工程,根目录下新建lib目录,添加hadoop和常用的jar包
 
- 编写自定义InputFormat(MutilCharInputFormat)
-  编写自定义MutilCharRecordReader实现RecordReader接口,并重写next方法