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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T21:07:35+00:00 2026-06-17T21:07:35+00:00

I’ve written a code which does something similar to SQL GroupBy. The dataset I

  • 0

I’ve written a code which does something similar to SQL GroupBy.

The dataset I took is here:


250788681419,20090906,200937,200909,619,SUNDAY,WEEKEND,ON-NET,MORNING,OUTGOING,VOICE,25078,PAY_AS_YOU_GO_PER_SECOND_PSB,SUCCESSFUL-RELEASEDBYSERVICE,17,0,1,21.25,635-10-112-30455


public class MyMap extends Mapper<LongWritable, Text, Text, DoubleWritable> {

public void map(LongWritable key, Text value, Context context) throws IOException 
{

        String line = value.toString();
        String[] attribute=line.split(",");
        double rs=Double.parseDouble(attribute[17]);

        String comb=new String();
        comb=attribute[5].concat(attribute[8].concat(attribute[10]));

            context.write(new Text(comb),new DoubleWritable (rs));

    }
 } 
public class MyReduce extends Reducer<Text, DoubleWritable, Text, DoubleWritable> {

protected void reduce(Text key, Iterator<DoubleWritable> values, Context context) 
          throws IOException, InterruptedException {

             double sum = 0;
             Iterator<DoubleWritable> iter=values.iterator();
                while (iter.hasNext()) 
                {
                    double val=iter.next().get();
                    sum = sum+ val;
                }
                context.write(key, new DoubleWritable(sum));
        };
     }

In the Mapper, as its value sends the 17th argument to the reducer to sum it. Now I also want to sum the 14th argument how do i send it to the reducer?

  • 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-17T21:07:36+00:00Added an answer on June 17, 2026 at 9:07 pm

    If your data types are the same, then creating an ArrayWritable class should work for this. The class should resemble:

    public class DblArrayWritable extends ArrayWritable 
    { 
        public DblArrayWritable() 
        { 
            super(DoubleWritable.class); 
        }
    }
    

    Your mapper class then looks like:

    public class MyMap extends Mapper<LongWritable, Text, Text, DblArrayWritable> 
    {
      public void map(LongWritable key, Text value, Context context) throws IOException 
      {
    
        String line = value.toString();
        String[] attribute=line.split(",");
        DoubleWritable[] values = new DoubleWritable[2];
        values[0] = Double.parseDouble(attribute[14]);
        values[1] = Double.parseDouble(attribute[17]);
    
        String comb=new String();
        comb=attribute[5].concat(attribute[8].concat(attribute[10]));
    
        context.write(new Text(comb),new DblArrayWritable.set(values));
    
      }
    }
    

    In your reducer you should now be able to iterate over the values of the DblArrayWritable.

    Based on your sample data however it looks like they may be separate types. You may be able to implement an ObjectArrayWritable class that would do the trick, but I’m not certain of this and I can’t see much to support it. If it works the class would be:

    public class ObjArrayWritable extends ArrayWritable 
    { 
        public ObjArrayWritable() 
        { 
            super(Object.class); 
        }
    }
    

    You could handle this by simply concatenating the values and passing them as Text to the reducer which would then split them again.

    Another option is to implement your own Writable class. Here’s a sample of how that could work:

    public static class PairWritable implements Writable 
    {
       private Double myDouble;
       private String myString;
    
        // TODO :-  Override the Hadoop serialization/Writable interface methods
        @Override
        public void readFields(DataInput in) throws IOException {
                myLong = in.readDouble();
                myString = in.readUTF();
        }
    
        @Override
        public void write(DataOutput out) throws IOException {
                out.writeDouble(myLong);
                out.writeUTF(myString);
        }
    
        //End of Implementation
    
        //Getter and Setter methods for myLong and mySring variables
        public void set(Double d, String s) {
            myDouble = d;
            myString = s;
        }
    
        public Long getLong() {
            return myDouble;
        }
        public String getString() {
            return myString;
        }
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am trying to understand how to use SyndicationItem to display feed which is
I used javascript for loading a picture on my website depending on which small
I have this code to decode numeric html entities to the UTF8 equivalent character.
I would like to run a str_replace or preg_replace which looks for certain words
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I have an autohotkey script which looks up a word in a bilingual dictionary
I have an array which has BIG numbers and small numbers in it. I
I have a text area in my form which accepts all possible characters from

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.