pig---用戶自定義函數(UDF)

用戶自定義函數(UDF)  
public abstract class EvalFunc<T> {  
  public abstract T exec(Tuple input) throws IOException;  
  public List<FuncSpec> getAvgToFuncMapping() throws FrontendException;  
  public FuncSpec outputSchema() throws FrontendException;  }  
輸入元組的字段包含傳遞給函數的表達式,輸出是泛型;對於過濾函數輸出就是Boolean類型。建議儘可能在 
getAvgToFuncMapping()/outputSchema()申明輸入和輸出數據的類型,以便Pig進行類型轉換或過濾不匹配類型的錯誤值。  
Grunt>REGISTER pig-examples.jar;  
          DEFINE isGood org.hadoopbook.pig.IsGoodQuality();  
加載UDF  
public LoadFunc {  
    public void setLocation(String location, Job job);  
    public InputFormat getInputFormat();  
    public void prepareToRead(RecordReader reader, PigSplit split);  
    public Tuple next() throws IOException;  }  
相似Hadoop,Pig的數據加載先於mapper的運行,因此保證數據能夠被分割成能被各個mapper獨立處理的部分很是重要。從Pig 0.7開始, 
加載和存儲函數接口已經進行了大幅修改,以便與Hadoop的InputFormat和OutputFormat類基本一致。  
Grunt>Register loadfunc.jar  
          Define customLoad org.hadoopbook.pig.loadfunc()  
          records = load ‘input/sample.txt’ using customLoad(‘16-19, 88-92, 93-93’)  
web

                         as (year:int, temperature:int, quality:int);微信

更多精彩內容請關注:http://bbs.superwu.cnapp

關注超人學院微信二維碼:函數

相關文章
相關標籤/搜索