pig REPLACE 给出错误
Posted
技术标签:
【中文标题】pig REPLACE 给出错误【英文标题】:pig REPLACE gives error 【发布时间】:2013-06-24 23:51:40 【问题描述】:假设我的文件名为“data”,如下所示:
2343234 23.8375,-2.339921102 (343.34333,-2.0000022) 5-23-2013-11-am
我需要将第二个字段转换为一对坐标数。所以我写了下面的代码并将其命名为basic.pig:
A = LOAD 'data' AS (f1:int, f2:chararray, f3:chararray. f4:chararray);
B = foreach A generate STRSPLIT(f2,',').$0 as f5, STRSPLIT(f2,',').$1 as f6;
C = foreach B generate REPLACE(f5,'',' ') as f7, REPLACE(f6,'',' ') as f8;
然后使用 (float) 将字符串转换为浮点数。但是,命令 'REPLACE' 不起作用,我收到以下错误:
-bash-3.2$ pig -x local basic.pig
2013-06-24 16:38:45,030 [main] INFO org.apache.pig.Main - Apache Pig version 0.11.1 (r1459641) compiled
Mar 22 2013, 02:13:53 2013-06-24 16:38:45,031 [main] INFO org.apache.pig.Main - Logging error messages to: /home/--/p/--test/pig_1372117125028.log
2013-06-24 16:38:45,321 [main] INFO org.apache.pig.impl.util.Utils - Default bootup file /home/isl/pmahboubi/.pigbootup not found
2013-06-24 16:38:45,425 [main] INFO org.apache.pig.backend.hadoop.executionengine.HExecutionEngine - Connecting to hadoop file system at: file:///
2013-06-24 16:38:46,069 [main] ERROR org.apache.pig.tools.grunt.Grunt - ERROR 1000: Error during parsing. Lexical error at line 7, column 0. Encountered: <EOF> after : ""
Details at logfile: /home/--/p/--test/pig_1372117125028.log
这是 pig_137..log 的详细信息
Pig Stack Trace
---------------
ERROR 1000: Error during parsing. Lexical error at line 7, column 0. Encountered: <EOF> after : ""
org.apache.pig.tools.pigscript.parser.TokenMgrError: Lexical error at line 7, column 0. Encountered: <EOF> after : ""
at org.apache.pig.tools.pigscript.parser.PigScriptParserTokenManager.getNextToken(PigScriptParserTokenManager.java:3266)
at org.apache.pig.tools.pigscript.parser.PigScriptParser.jj_ntk(PigScriptParser.java:1134)
at org.apache.pig.tools.pigscript.parser.PigScriptParser.parse(PigScriptParser.java:104)
at org.apache.pig.tools.grunt.GruntParser.parseStopOnError(GruntParser.java:194)
at org.apache.pig.tools.grunt.GruntParser.parseStopOnError(GruntParser.java:170)
at org.apache.pig.tools.grunt.Grunt.exec(Grunt.java:84)
at org.apache.pig.Main.run(Main.java:604)
at org.apache.pig.Main.main(Main.java:157)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.apache.hadoop.util.RunJar.main(RunJar.java:197)
================================================================================
【问题讨论】:
【参考方案1】:我有这样的数据:
2724 1919 2012-11-18T23:57:56.000Z (33.80981975),(-118.105289)
2703 6401 2012-11-18T23:57:56.000Z (55.83525609),(-4.07733138)
1200 4015 2012-11-18T23:57:56.000Z (41.49609152),(13.8411998)
7104 9227 2012-11-18T23:57:56.000Z (-24.95351118),(-53.46538723)
我可以这样做:
A = LOAD 'my_tsv_data' USING PigStorage('\t') AS (id1:int, id2:int, date:chararray, loc:chararray);
B = FOREACH A GENERATE REPLACE(loc,'\\|\\|\\(|\\)','');
C = LIMIT B 10;
DUMP C;
【讨论】:
【参考方案2】:这个错误
ERROR 1000: Error during parsing. Lexical error at line 7, column 0. Encountered: <EOF> after : ""
来找我是因为我使用了不同类型的引号。我以 ' 开头并以 ' 或 ` 结尾,花了很长时间才发现出了什么问题。所以它与第 7 行无关(我的脚本没有那么长,我将数据缩短到四行自然没有帮助),与第 0 列无关,与数据的 EOF 无关,几乎没有任何关系使用我没有使用的 " 标记。所以非常具有误导性的错误消息。
我通过使用 grunt - pig 命令 shell 找到了原因。
【讨论】:
这个答案拯救了我的一天。这是一个非常具有误导性的错误消息。以上是关于pig REPLACE 给出错误的主要内容,如果未能解决你的问题,请参考以下文章
Replace Child 给出错误(未能在节点上执行“replacechild”)?
Python,使用 print() 和 replace() 函数来解释字符串给出的代码
mpdf 错误 - preg_replace(): /e 修饰符已弃用,请改用 preg_replace_callback