Skip to content

Instantly share code, notes, and snippets.

@tf0054
Created March 22, 2012 14:52
Show Gist options
  • Save tf0054/2158768 to your computer and use it in GitHub Desktop.
Save tf0054/2158768 to your computer and use it in GitHub Desktop.
Hack#48
package org.hadoophacks.pig;
import java.io.IOException;
import org.apache.pig.FilterFunc;
import org.apache.pig.data.Tuple;
import org.apache.pig.backend.executionengine.ExecException;
public class MyMatches extends FilterFunc{
public Boolean exec(Tuple input)throws IOException{
if(input == null || input.size() != 2){
return false;
}
try{
Object arg0 = input.get(0);
Object arg1 = input.get(1);
if(arg0 == null || arg1 == null || !(arg0 instanceof String) || !(arg1 instanceof String)){
return false;
}
String str = (String)arg0;
String pattern = (String)arg1;
return str.matches(pattern);
}
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