1. 程式人生 > >hive如何處理多分隔符資料

hive如何處理多分隔符資料

問題描述:     大資料維穩需求中,客戶提供的測試資料為多個字元做分隔符('|#'),在pig中會直接報錯,hive中只認第一個分隔符。 由於資料量比較大(160G),在文字中替換成單個字元分隔符已不現實,以下提供兩個方案解決這一問題。 樣例資料 110|#警察 120|#醫院 方案1:利用hive自帶的序列化/反序列化的方式RegexSe  add jar /home/cup/software/……/hive-contrib-0.10.0-cdh4.4.0.jar; create table test ( id string, name string )partitioned by (c_day string) row format serde 'org.apache.hadoop.hive.contrib.serde2.RegexSerDe' with serdeproperties ( 'input.regex' = '([^\\|#]*)\\|#([^\\|#]*)' , 'output.format.string' = '%1$s%2$s') stored as textfile; load data local inpath '/……/test.txt'  overwrite into table test partition(c_day = '20141027'); select * from test; 110 警察 20141027 120 醫院 20141027 ========================================================== 方案2:重寫相應的InputFormat和OutputFormat方法