当我尝试这个时,它起作用了:
B = FOREACH A {
X = STRSPLIT(agegroup,'-',0);
}
输出:
((20,30))
((20+))
((20,40))
and so on...
现在,我尝试FLATTEN
这样:
B = FOREACH A {
X = FLATTEN(STRSPLIT(agegroup,'-',0));
}
我收到以下错误:
Pig Stack Trace
---------------
ERROR 1200: <file PigScript.pig, line 3, column 5> Syntax error, unexpected symbol at or near 'FLATTEN'
org.apache.pig.impl.logicalLayer.FrontendException: ERROR 1000: Error during parsing. <file PigScript.pig, line 3, column 5> Syntax error, unexpected symbol at or near 'FLATTEN'
at org.apache.pig.PigServer$Graph.parseQuery(PigServer.java:1701)
at org.apache.pig.PigServer$Graph.access$000(PigServer.java:1421)
at org.apache.pig.PigServer.parseAndBuild(PigServer.java:354)
at org.apache.pig.PigServer.executeBatch(PigServer.java:379)
at org.apache.pig.PigServer.executeBatch(PigServer.java:365)
at org.apache.pig.tools.grunt.GruntParser.executeBatch(GruntParser.java:140)
at org.apache.pig.tools.grunt.GruntParser.processDump(GruntParser.java:769)
at org.apache.pig.tools.pigscript.parser.PigScriptParser.parse(PigScriptParser.java:372)
at org.apache.pig.tools.grunt.GruntParser.parseStopOnError(GruntParser.java:198)
at org.apache.pig.tools.grunt.GruntParser.parseStopOnError(GruntParser.java:173)
at org.apache.pig.tools.grunt.Grunt.exec(Grunt.java:84)
at org.apache.pig.Main.run(Main.java:613)
at org.apache.pig.Main.main(Main.java:158)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.apache.hadoop.util.RunJar.run(RunJar.java:221)
at org.apache.hadoop.util.RunJar.main(RunJar.java:136)
Caused by: Failed to parse: <file PigScript.pig, line 3, column 5> Syntax error, unexpected symbol at or near 'FLATTEN'
at org.apache.pig.parser.QueryParserDriver.parse(QueryParserDriver.java:241)
at org.apache.pig.parser.QueryParserDriver.parse(QueryParserDriver.java:179)
at org.apache.pig.PigServer$Graph.parseQuery(PigServer.java:1688)
... 18 more
================================================================================
请告诉我哪里弄错了。
答案 0 :(得分:1)
您不能在嵌套的FOREACH块中使用FLATTEN。在嵌套的FOREACH块中只允许使用CROSS,DISTINCT,FILTER,FOREACH,LIMIT和ORDER BY。
更改
B = FOREACH A {
X = FLATTEN(STRSPLIT(agegroup,'-',0));
}
要
B = FOREACH A GENERATE FLATTEN(STRSPLIT(agegroup,'-',0));