Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 710239
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T04:35:40+00:00 2026-05-14T04:35:40+00:00

I have a User Defined Function (UDF) written in Java to parse lines in

  • 0

I have a User Defined Function (UDF) written in Java to parse lines in a log file and return information back to pig, so it can do all the processing.

It looks something like this:

public abstract class Foo extends EvalFunc<Tuple> {
    public Foo() {
        super();
    }

    public Tuple exec(Tuple input) throws IOException {
        try {
            // do stuff with input
        } catch (Exception e) {
            throw WrappedIOException.wrap("Error with line", e);
        }
    }
}

My question is: if it throws the IOException, will it stop completely, or will it return results for the rest of the lines that don’t throw an exception?

Example: I run this in pig

REGISTER myjar.jar
DEFINE Extractor com.namespace.Extractor();

logs = LOAD '$IN' USING TextLoader AS (line: chararray);
events = FOREACH logs GENERATE FLATTEN(Extractor(line));

With this input:

1.5 7 "Valid Line"
1.3 gghyhtt Inv"alid line"" I throw an exceptioN!!
1.8 10 "Valid Line 2"

Will it process the two lines and will ‘logs’ have 2 tuples, or will it just die in a fire?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T04:35:40+00:00Added an answer on May 14, 2026 at 4:35 am

    If the exception is thrown by the UDF the task will fail and will be retried.

    It will fail again three more times (4 attempts by default) and the whole job will be FAILED.

    If you want to log the error and do not want to have the Job stopped you can return a null:

    public Tuple exec(Tuple input) throws IOException {
        try {
            // do stuff with input
        } catch (Exception e) {
            System.err.println("Error with ...");
            return null;
        }
    }
    

    And filter them later in Pig:

    events_all = FOREACH logs GENERATE Extractor(line) AS line;
    events_valid = FILTER events_all by line IS NOT null;
    events = FOREACH events_valid GENERATE FLATTEN(line);
    

    In your example the output will only have the two valid lines (but be careful with this behavior as the error is only present in the logs and won’t fail your job!).

    Reply to comment #1:

    Actually, the whole resultant tuple would be null (so there is no fields inside).

    For example if your schema has 3 fields:

     events_all = FOREACH logs
                  GENERATE Extractor(line) AS line:tuple(a:int,b:int,c:int);
    

    and some lines are incorrect we would get:

     ()
     ((1,2,3))
     ((1,2,3))
     ()
     ((1,2,3))
    

    And if you don’t filter the null line and try to access a field you get a java.lang.NullPointerException:

    events = FOREACH events_all GENERATE line.a;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Most systems will have a user-defined function (UDF) available. Some will not. i want
I have had quite some difficulty trying to make a User Defined Function (UDF)
I have this user defined function. public partial class UserDefinedFunctions { static int i;
I have an user defined table function in SQL Server that aggregate data from
I have a table a with a list of id's, and a user-defined function
I have a user defined function (e.g. myUDF(a,b) ) that returns an integer. I
I have a user defined function. In that function I declared a variable of
I have a user defined function which is used in many stored procedures which
Is it possible that a multi-statement UDF return a User Defined Table Type, instead
I have this problem whereby, i have created a user defined function within php.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.