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 8734017
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T09:45:40+00:00 2026-06-13T09:45:40+00:00

A sqoop query generates a java file that contains a class that contains the

  • 0

A sqoop query generates a java file that contains a class that contains the code to get access in mapreduce to the columns data for each row. (the Sqoop import was done in text without the –as-sequencefile option, and with 1 line per record and commas between the columns)
But how do we actually use it?

I found a public method parse() in this class that takes Text as an input and populates all the members of the class , so to practice I modified the wordcount application to convert a line of text from the TextInputFormat in the mapper into an instnace of the class generated by sqoop. But that causes an “unreported exception.com.cloudera.sqoop.lib.RecordParser.ParseError; must be caught or declared to be thrown” when I call the parse() method.

Can it be done this way or is a custom InputFormat necessary to populate the class with the data from each record ?

  • 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-13T09:45:41+00:00Added an answer on June 13, 2026 at 9:45 am

    Ok this seems obvious once you find out but as a java beginner this can take time.

    First configure your project:
    just add the sqoop generated .java file in your source folder.
    I use eclipse to import it in my class source folder.

    Then just make sure you configured your project’s java build path correctly:

    Add the following jar files in the project’s properties/java build path/libraries/add external jar:
    (for hadoop cdh4+) :

    /usr/lib/hadoop/hadoop-common.jar 
    /usr/lib/hadoop-[version]-mapreduce/hadoop-core.jar
    /usr/lib/sqoop/sqoop-[sqoop-version]-cdh[cdh-version].jar
    

    Then adapt your mapreduce source code:
    First configure it:

    public int run(String [] args) throws exception
    {
     Job job = new Job(getConf());
     job.setJarByClass(YourClass.class);
     job.setMapperClass(SqoopImportMap.class);
     job.setReducerClass(SqoopImprtReduce.class);
    
     FileInputFormat.addInputPath((job,"hdfs_path_to_your_sqoop_imported_file"));
     FileOutputFormat.setOutputPath((job,"hdfs_output_path"));
    
     // I simply use text as output for the mapper but it can be any class you designed
     // as long as you implement it as a Writable
     job.setMapOutputKeyClass(Text.Class);
     job.setMapOutputValueClass(Text.Class);
    
     job.setOutputKeyClass(Text.Class);
     job.setOutputValueClass(Text.Class);
     ...
    

    Now configure your mapper class.
    Let’s assume your sqoop imported java file is called Sqimp.java:
    and the table you imported had the following columns: id, name, age
    your mapper class should look like this:

     public static class SqoopImportMap
     extends Mapper<LongWritable, Text, Text, Text> 
     {
    
     public void map(LongWritable k, Text v, Context context)
     {
      Sqimp s = new Sqimp(); 
      try
      {
      // this is where the code generated by sqoop is used.
      // it automatically casts one line of the imported data into an instance of the generated class, 
      // to let you access the data inside the columns easily
       s.parse(v);
      } 
      catch(ParseError pe) {// do something if there is an error.}
    
      try
      {
       // now the imported data is accessible:
       // e.g
       if (s.age>30)
       {
        // submit the selected data to the mapper's output as a key value pair.
        context.write(new Text(s.age),new Text(s.id));
       }
      }
      catch(Exception ex)
      {//do something about the error}
     }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a gridview that is bound to the result from an nhibernate query.
We have a database that has a bunch of records with some bad data
I am trying to snoop on a log file that an application is writing
My Use Case: I want to import the large data from EC2 through SQOOP
How to import data from mysql to HDFS. I can't use sqoop as it's
I have added the following: export SQOOP_HOME=/usr/bin/ to my /etc/profile file. However when I
So here's the scoop: I wrote a tiny C# app a while back that
I have a list of files with numeric file names (e.g. #.php, ##.php or
I know how to use sqoop through command line. But dont know how to
What are some useful utilities that help you when writing WPF applications? I know

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.