替换猪中的字符 [英] Replace character in pig
本文介绍了替换猪中的字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的数据格式如下..
{"Foo":"ABC","Bar":"20090101100000","Quux":"{\"QuuxId\":1234,\"QuuxName\":\"Sam\"}"}
我需要它采用这种格式:
I need it to be in this format:
{"Foo":"ABC","Bar":"20090101100000","Quux":{"QuuxId":1234,"QuuxName":"Sam"}}
我正在尝试使用 Pig 的替换功能以我需要的格式获取它.所以,我试过了..
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.
真诚地感谢任何帮助..
Any help is sincerely appreciated..
谢谢
推荐答案
为我工作:
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屋!
查看全文