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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T18:28:58+00:00 2026-05-29T18:28:58+00:00

I have a huge CSV file I would like to process using Hadoop MapReduce

  • 0

I have a huge CSV file I would like to process using Hadoop MapReduce on Amazon EMR (python).

The file has 7 fields, however, I am only looking at the date and quantity field.

 "date" "receiptId" "productId" "quantity"  "price" "posId" "cashierId"

Firstly, my mapper.py

import sys

def main(argv):
    line = sys.stdin.readline()
    try:
        while line:
            list = line.split('\t')

            #If date meets criteria, add quantity to express key
                if int(list[0][11:13])>=17 and int(list[0][11:13])<=19:
                    print '%s\t%s' % ("Express", int(list[3]))
            #Else, add quantity to non-express key
                else:
                    print '%s\t%s' % ("Non-express", int(list[3]))

            line =  sys.stdin.readline()
except "end of file":
        return None
if __name__ == "__main__":
        main(sys.argv)

For the reducer, I will be using the streaming command: aggregate.

Question:

  1. Is my code right? I ran it in Amazon EMR but i got an empty output.

  2. So my end result should be: express, XXX and non-express, YYY. Can I have it do a divide operation before returning the result? Just the result of XXX/YYY. Where should i put this code? A reducer??

  3. Also, this is a huge CSV file, so will mapping break it up into a few partitions? Or do I need to explicitly call a FileSplit? If so, how do I do that?

  • 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-29T18:28:58+00:00Added an answer on May 29, 2026 at 6:28 pm

    Answering my own question here!

    1. The code is wrong. If you’re using aggregate library to reduce, your output does not follow the usual key value pair. It requires a “prefix”.

      if int(list[0][11:13])>=17 and int(list[0][11:13])<=19:
          #This is the correct way of printing for aggregate library
          #Print all as a string.
          print  "LongValueSum:" + "Express" + "\t" + list[3]
      

      The other “prefixes” available are: DoubleValueSum, LongValueMax, LongValueMin, StringValueMax, StringValueMin, UniqValueCount, ValueHistogram. For more info, look here http://hadoop.apache.org/common/docs/r0.15.2/api/org/apache/hadoop/mapred/lib/aggregate/package-summary.html.

    2. Yes, if you want to do more than just the basic sum, min, max or count, you need to write your own reducer.

    3. I do not yet have the answer.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have to write huge data in text[csv] file. I used BufferedWriter to write
I have a huge collection of visual foxpro dbf files that I would like
Let's say I have a dictionary of names (a huge CSV file). I want
I have huge table with 1 million records, i would like to modify some
I have a 10GB CSV file which is essentially a huge square matrix. I
In Python, I have an application that writes a list to a CSV file,
Scenario: I have a huge .csv file (million of lines) . With sqlldr (SQL
I have a UTF-16 CSV file which I have to read. Python csv module
I have loaded a huge CSV dataset -- Eclipse's Filtered Usage Data using PostgreSQL's
I have a huge file, where I have to insert certain characters at a

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.