Created
March 22, 2012 14:51
-
-
Save tf0054/2158761 to your computer and use it in GitHub Desktop.
Hack#48
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package org.hadoophacks.pig; | |
import org.apache.pig.EvalFunc; | |
import org.apache.pig.data.Tuple; | |
import org.apache.pig.data.DataType; | |
import org.apache.pig.backend.executionengine.ExecException; | |
import org.apache.pig.impl.logicalLayer.schema.Schema; | |
import org.apache.pig.impl.logicalLayer.FrontendException; | |
import java.io.IOException; | |
import java.util.List; | |
import java.util.ArrayList; | |
import org.apache.pig.FuncSpec; | |
import org.hadoophacks.pig2.DoubleAbs; | |
public class Abs extends EvalFunc<Integer>{ | |
public Integer exec(Tuple input)throws IOException{ | |
if(input == null || input.size() == 0){ | |
return null; | |
} | |
try{ | |
Integer value = (Integer)input.get(0); | |
return Math.abs(value); | |
}catch(ExecException e){ | |
throw new IOException(e); | |
} | |
} | |
public List<FuncSpec> getArgToFuncMapping()throws FrontendException{ | |
List<FuncSpec> funcList = new ArrayList<FuncSpec>(); | |
funcList.add(new FuncSpec(this.getClass().getName() , new Schema(new Schema.FieldSchema(null , DataType.INTEGER)))); | |
funcList.add(new FuncSpec(DoubleAbs.class.getName() , new Schema(new Schema.FieldSchema(null , DataType.DOUBLE)))); | |
return funcList; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment