如何重命名包中的字段

时间:2014-06-10 13:38:56

标签: hadoop apache-pig

如何重命名包中的字段。我已经found投影字段了,但是我无法重命名它们。

例如:

renamed = FOREACH named GENERATE
   field0,
   elements.(
      field1,
      field2 
   );

如果我尝试以下操作,我收到了一个错误:

renamed = FOREACH named GENERATE
   field0,
   elements.(
      field1 AS renamed1,
      field2 
   );

错误消息如下

2014-06-10 08:34:14,701 [main] ERROR org.apache.pig.tools.grunt.Grunt - ERROR 1200: <line 233, column 16>  mismatched input 'AS' expecting RIGHT_PAREN
2014-06-10 08:34:14,702 [main] WARN  org.apache.pig.tools.grunt.Grunt - There is no log file to write to.
2014-06-10 08:34:14,702 [main] ERROR org.apache.pig.tools.grunt.Grunt - Failed to parse: <line 233, column 16>  mismatched input 'AS' expecting RIGHT_PAREN
    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.validateQuery(PigServer.java:1648)
    at org.apache.pig.PigServer$Graph.registerQuery(PigServer.java:1621)
    at org.apache.pig.PigServer.registerQuery(PigServer.java:575)
    at org.apache.pig.tools.grunt.GruntParser.processPig(GruntParser.java:1093)
    at org.apache.pig.tools.pigscript.parser.PigScriptParser.parse(PigScriptParser.java:501)
    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.run(Grunt.java:69)
    at org.apache.pig.Main.run(Main.java:541)
    at org.apache.pig.Main.main(Main.java:156)
    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.main(RunJar.java:212)

1 个答案:

答案 0 :(得分:2)

您需要在定义行李后放置AS子句。试试这个:

renamed = FOREACH named GENERATE
   field0,
   elements.(
      field1
      field2 
   ) AS bagName:{(renamed1, renamed2)};