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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T15:18:54+00:00 2026-06-17T15:18:54+00:00

I am trying to read a file which has lines in the following format.

  • 0

I am trying to read a file which has lines in the following format.

100,1:2:3
200,10:20:30

Assuming that the inputs will always be numbers, I am trying to read the file by setting the input key and value as IntWritable and Text respectively. But when I run it, I get the following error:

java.lang.ClassCastException: org.apache.hadoop.io.Text cannot be cast to org.apache.hadoop.io.IntWritable

Now, though I understand what it means, I am unable to figure out how to read the key as an integer. The code runs fine if I read the key as a Text as well. I have checked everywhere in the code if I have missed the configuration, but it seems fine to me.

conf.set("mapred.textoutputformat.separator", "|");

conf.setInputFormatClass(KeyValueTextInputFormat.class);
conf.setOutputFormatClass(TextOutputFormat.class);

conf.setOutputKeyClass(IntWritable.class);
conf.setOutputValueClass(Text.class);

I have also checked the mapper class and methods (There is no reducer). Is it that the KeyValueTextInputFormat can read the key as only Text? I am unable to understand what I am doing wrong. Any help would be deeply appreciated.

Thanks,
EG

  • 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-17T15:18:56+00:00Added an answer on June 17, 2026 at 3:18 pm

    Looking at the source of KeyValueTextInputFormat, it extends from FileInputFormat<Text, Text>. What that means is that both key and value for your input are expected to be Text.

    You could fix that implementing your own RecordReader which you could model after the KeyValueLineRecordReder described here, but extend from RecordReader<IntWritable, Text> instead and modify the code accordingly.

    When you have your RecordReader, you can create your own InputFormat and use your new RecordReader and then in your main code you just need to set your new InputFormat like this:

    conf.setInputFormatClass(KeyValueMyInputFormat.class);
    

    Another approach I would recommend if you’re really worried about performance is that you could use SequenceFileInputFormat. This involves storing your input as SequenceFiles, which means it will be in binary format directly. This avoids the overhead of parsing every line as you need to do in your case. You can use this format like this:

    conf.setInputFormatClass(SequenceFileInputFormat.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 read the file with the following format which repeats itself
I am trying to read a file which has several lines and print it
I am trying to read a text file in MATLAB which has a format
I am trying to write some simple code which will read a text file
I'm trying to read and handle a web-page in Python which has lines like
I am trying to read a file which has say Name,Date,Place Tom,1/1/2010,America Dick,2/2/2011,China Harry,3/3/2012,Germany
I am trying to read from a file that has comma seperated values like
I am trying to read a file of over 1GB (which has 1,157,421,364 bytes),
So I am trying to read in a file that has a bunch of
I am trying to read a html file which is a plain page with

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.