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

  • SEARCH
  • Home
  • 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 8735841
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T10:09:52+00:00 2026-06-13T10:09:52+00:00

I am new into java world.. But basically I am trying to write a

  • 0

I am new into java world.. But basically I am trying to write a user-defined-function in pig-latin.

The following is the relevant code.

public class time extends EvalFunc<String>{

public String exec(Tuple input) throws IOException {

    if ((input == null) || (input.size() == 0))
        return null;
    try{
        String time = (String) input.get(0) ;
        DateFormat df = new SimpleDateFormat("hh:mm:ss.000");
        Date date = df.parse(time);
        String timeOfDay = getTimeOfDay(date);
        return timeOfDay;
    } catch (IOException e) {
        throw e;
    }

}

So basically input is a tuple… I do a check whether the tuple is empty or not..
And then get convert that date string to time object.. and then parse the time part..
and then the function

  getTimeOfDay(date) returns a string... like breakfast, lunch dinner.. or empty string depending on the time hours..

Now the issue is that my eclipse says and error (red line) in

 Date date = df.parse(time);
 String timeOfDay = getTimeOfDay(date);

says

 Unhandled exception type ParseException

But no matter what I try (gives me 3 options.. add catch clause to surrounding try, add exception to existing catch block and surround with try/catch..), the error shifts.. but is always tehre.

And i am not even sure that I can change the structure of program..(the method declaration etc)..

How do I resolve this.

  A quick guide on udf http://wiki.apache.org/pig/UDFManual

If you know pig.. or knows an easy method.. then basically what i am trying to do is .. given an input string of type “time,id,amount” check at what time of the day the transaction was made?

THanks

  • 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-06-13T10:09:53+00:00Added an answer on June 13, 2026 at 10:09 am
    • If your exec method is already declared to throw IOException, you do not need to catch it and throw it as the throws declaration will automatically do that.
    • As for ParseException you have to decide how to handle it.
    • Also a bracket was missing =)

    So your code should be:

    public class time extends EvalFunc<String>{
    
    public String exec(Tuple input) throws IOException {
    
        if ((input == null) || (input.size() == 0))
            return null;
        try{
            String time = (String) input.get(0) ;
            DateFormat df = new SimpleDateFormat("hh:mm:ss.000");
            Date date = df.parse(time);
            String timeOfDay = getTimeOfDay(date);
            return timeOfDay;
        } catch (ParseException e) {
            //how will I handle when df.parse(time) fails and throws ParseException?
            //maybe:
            return null;
        }
      } //exec
    
    } //class
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to add a new column into an SQLiteDatabase but every time
I am trying to import java.awt.*; into my class in Greenfoot but when I
I am new to coding in Objective-C, but am coming from the Java world
Executive summary: how do I install a new root certificate into Java using Java
I'm new to Java and have gotten myself into a situation where it's evident
I'm new to Java. I want to create Java Array and insert data into
am new to this java world.. i just wanted to know how to convert
first of all, i'm learning scala and new to the java world. I want
I am new in embedded world. May be I am wrong. But I want
I'm relatively new in the Java world and I have a problem which I

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.