Krishna Kalyan
Krishna Kalyan

Reputation: 1702

Pig UDF not being able to filter words

I have a file with tweets i want to extract all tweets with my filters however i get an error

public class TweetFilter extends FilterFunc {
    static List<String> filterList;

    TweetFilter() {
        filterList.add("sick");
        // Many More Filters
    }

    public Boolean exec(Tuple input) throws IOException {
        if (input == null || input.size() == 0)
            return null;
        try {
            String str = (String) input.get(0);
            if (filterList.contains(str)) {
                return true;
            } else {
                return false;
            }

        } catch (Exception e) {
            throw new IOException("Caught exception processing input row ", e);
        }
    }
}

B = FILTER A BY UDF.TweetFilter($0);

Error : could not instantiate 'UDF.TweetFilter' with arguments 'null'

Upvotes: 0

Views: 149

Answers (2)

Paul S
Paul S

Reputation: 494

You should register the jar which contains your filter before trying to call it from your pig script, if you haven't done so already

Try adding:

register myudfs.jar;

As explainded in de UDFManual http://wiki.apache.org/pig/UDFManual

Upvotes: 0

Frederic
Frederic

Reputation: 3284

If that is the entire code then your filterList will be null resulting in a NullPointerException when calling filteList.add("sick").

To resolve this, modify the line

 static List<String> filterList;

to

List<String> filterList = new LinkedList<String>();

Also, make your constructor public.

Could not instantiate is usually the error message you get when something goes wrong when calling the UDF's constructor.

Upvotes: 1

Related Questions