Error

An error occurred.

Sorry, the page you are looking for is currently unavailable.
Please try again later.

If you are the system administrator of this resource then you should check the error log for details.

Faithfully yours, nginx.

帮助文档(华北一、二)

  • ● 准备数据

    student 文件内容

     
    any 9 5 
    bob 8 4

    上传student文件

     hdfs dfs -put student /user/root/student

    ● 示例代码

     
    package myudfs; 
    import java.io.IOException; 
    import org.apache.pig.EvalFunc; 
    import org.apache.pig.data.Tuple;   
    public class UPPER extends EvalFunc<String> 
    {     
      public String exec(Tuple input) throws IOException {         
        if (input == null || input.size() == 0 || input.get(0) == null)             
          return null;         
        try{             
          String str = (String)input.get(0);             
          return str.toUpperCase();        
        }catch(Exception e){             
          throw new IOException("Caught exception processing input row ", e);         
        }     
      } 
    }

    ● 编译

     
    cd myudfs 
    javac -cp $ PIG_HOME/pig-0.12.0-cdh5.4.4.jar UPPER.java 
    cd .. 
    jar -cf myudfs.jar myudfs

    测试脚本upper.pig

     
    REGISTER myudfs.jar; 
    A = LOAD 'student' AS (name: chararray, age: int, gpa: float); 
    B = FOREACH A GENERATE myudfs.UPPER(name); 
    DUMP B;

    ● 执行

     pig upper.pig

    ● 输出结果

    (ANY 9 5) (BOB 8 4)。


文档是否已解决您的问题?

  已解决   未解决

如您有其它疑问,您也可以与我们技术专家联系探讨。

联系技术专家