我是PIG的新手,有人可以帮我如何加载带有多个字符(在我的情况下为'^^')作为列定界符的文件。
例如我有以下几列的文件
aisforapple ^^ bisforball ^^ cisforcat ^^ disfordoll ^^ andeisforelephant
fisforfish ^^ gisforgreen ^^ hisforhat ^^ iisforicecreem ^^ andjisforjar
kisforking ^^ lisforlion ^^ misformango ^^ nisfornose ^^ andoisfororange
问候
最佳答案
正则表达式最适合此类多种字符
input.txt
aisforapple^^bisforball^^cisforcat^^disfordoll^^andeisforelephant
fisforfish^^gisforgreen^^hisforhat^^iisforicecreem^^andjisforjar
kisforking^^lisforlion^^misformango^^nisfornose^^andoisfororange
PigScript
A = LOAD 'input.txt' AS line;
B = FOREACH A GENERATE FLATTEN(REGEX_EXTRACT_ALL(line,'(.*)\\^\\^(.*)\\^\\^(.*)\\^\\^(.*)\\^\\^(.*)')) AS (f1,f2,f3,f4,f5);
DUMP B;
Output:
(aisforapple,bisforball,cisforcat,disfordoll,andeisforelephant)
(fisforfish,gisforgreen,hisforhat,iisforicecreem,andjisforjar)
(kisforking,lisforlion,misformango,nisfornose,andoisfororange)
说明:
For better understanding i break the regex into multiple lines
(.*)\\^\\^ ->Any character match till ^^ and stored into f1,(double backslash for special characters)
(.*)\\^\\^ ->Any character match till ^^ and stored into f2,(double backslash for special characters)
(.*)\\^\\^ ->Any character match till ^^ and stored into f3,(double backslash for special characters)
(.*)\\^\\^ ->Any character match till ^^ and stored into f4,(double backslash for special characters)
(.*) ->Any character match till the end of string and stored into f5
关于hadoop - pig 自定义函数加载多个字符^^(双胡萝卜)定界符,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/26535051/