Created
March 22, 2012 14:52
-
-
Save tf0054/2158768 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 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