Skip to content

Instantly share code, notes, and snippets.

@tf0054
Created March 22, 2012 14:51
Show Gist options
  • Save tf0054/2158764 to your computer and use it in GitHub Desktop.
Save tf0054/2158764 to your computer and use it in GitHub Desktop.
Hack#48
package org.hadoophacks.pig2;
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;
public class DoubleAbs extends EvalFunc<Double>{
public Double exec(Tuple input)throws IOException{
if(input == null || input.size() == 0){
return null;
}
try{
Double value = (Double)input.get(0);
return Math.abs(value);
}catch(ExecException e){
throw new IOException(e);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment