替换猪中的字符 [英] Replace character in pig
本文介绍了替换猪中的字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的数据采用以下格式.
My data is in the following format..
{"Foo":"ABC","Bar":"20090101100000","Quux":"{\"QuuxId\":1234,\"QuuxName\":\"Sam\"}"}
我需要采用以下格式:
{"Foo":"ABC","Bar":"20090101100000","Quux":{"QuuxId":1234,"QuuxName":"Sam"}}
我正在尝试使用Pig的replace函数以所需的格式获取它. 所以,我尝试了..
I'm trying to using Pig's replace function to get it in the format I need.. So, I tried ..
"LOGS = LOAD 'inputloc' USING TextStorage() as unparsedString:chararray;;" +
"REPL1 = foreach LOGS REPLACE($0, '"{', '{');" +
"REPL2 = foreach REPL1 REPLACE($0, '}"', '}');"
"STORE REPL2 INTO 'outputlocation';"
它引发错误..表达式或语句中出现意外的标记'{'.
It throws an error.. Unexpected token '{' in expression or statement.
因此根据此处的答案,我尝试了:
So based on an answer here, I tried:
"REPL1 = foreach LOGS REPLACE($0, '"\\{', '\\{');"
现在,它给出了一个错误..表达式或语句中出现意外的标记'\\'.
Now, it gives an error.. Unexpected token '\\' in expression or statement.
衷心感谢您的帮助.
谢谢
推荐答案
为我工作:
REPL1 = FOREACH LOGS GENERATE REPLACE($0, '"\\{', '\\{');
在您的代码中,您缺少GENERATE
,并且在开头和结尾的双引号都是错误的.
In your code you are missing the GENERATE
and the double quotes at the beginning and end are wrong.
这篇关于替换猪中的字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文