pig自定义函数加载多个字符^^(双胡萝卜)分隔符



我是PIG的新手,有人能帮我如何加载一个以多个字符(在我的情况下是"^^")作为列分隔符的文件吗。

例如,我有一个包含以下列的文件苹果可以禁止所有的苹果不受欢迎fisforfish^^gisforgreen^^hisforhat^^^iiforicecreem^^^andjisfojarkisfforking^^lisforlion^^errorrmango^^nisfornose^^andisforrange

问候

Regex最适合这些类型的多字符

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

最新更新