Created
March 22, 2012 14:55
-
-
Save tf0054/2158802 to your computer and use it in GitHub Desktop.
Hack#48
This file contains hidden or 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.backend.executionengine.ExecException; | |
| import org.apache.pig.data.DataBag; | |
| import org.apache.pig.FuncSpec; | |
| import java.io.IOException; | |
| import org.apache.pig.impl.logicalLayer.schema.Schema; | |
| import org.apache.pig.impl.logicalLayer.FrontendException; | |
| import java.util.ArrayList; | |
| import org.apache.pig.data.DataType; | |
| import java.util.List; | |
| public class ToUpperCase extends EvalFunc<String>{ | |
| public String exec(Tuple input)throws IOException{ | |
| if(input == null || input.size() == 0){ | |
| return null; | |
| } | |
| try{ | |
| Object obj = input.get(0); | |
| if(obj == null || !(obj instanceof String)){ | |
| return null; | |
| } | |
| return ((String)obj).toUpperCase(); | |
| }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.CHARARRAY)))); | |
| return funcList; | |
| } | |
| } | |
| class ToUpperCaseInt extends EvalFunc<String>{ | |
| public String exec(Tuple input)throws IOException{ | |
| return input.get(0).toString(); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment