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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T09:25:46+00:00 2026-06-11T09:25:46+00:00

Suppose I have a tab delimited file containing user activity data formatted like this:

  • 0

Suppose I have a tab delimited file containing user activity data formatted like this:

timestamp  user_id  page_id  action_id

I want to write a hadoop job to count user actions on each page, so the output file should look like this:

user_id  page_id  number_of_actions

I need something like composite key here – it would contain user_id and page_id. Is there any generic way to do this with hadoop? I couldn’t find anything helpful. So far I’m emitting key like this in mapper:

context.write(new Text(user_id + "\t" + page_id), one);

It works, but I feel that it’s not the best solution.

  • 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-11T09:25:47+00:00Added an answer on June 11, 2026 at 9:25 am

    Just compose your own Writable. In your example a solution could look like this:

    public class UserPageWritable implements WritableComparable<UserPageWritable> {
    
      private String userId;
      private String pageId;
    
      @Override
      public void readFields(DataInput in) throws IOException {
        userId = in.readUTF();
        pageId = in.readUTF();
      }
    
      @Override
      public void write(DataOutput out) throws IOException {
        out.writeUTF(userId);
        out.writeUTF(pageId);
      }
    
      @Override
      public int compareTo(UserPageWritable o) {
        return ComparisonChain.start().compare(userId, o.userId)
            .compare(pageId, o.pageId).result();
      }
    
    }
    

    Although I think your IDs could be a long, here you have the String version. Basically just the normal serialization over the Writable interface, note that it needs the default constructor so you should always provide one.

    The compareTo logic tells obviously how to sort the dataset and also tells the reducer what elements are equal so they can be grouped.

    ComparisionChain is a nice util of Guava.

    Don’t forget to override equals and hashcode! The partitioner will determine the reducer by the hashcode of the key.

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

Sidebar

Related Questions

Hi suppose if i have a tab seperated file like this (each field separated
Suppose I have a table with data like: Tab(id, name) 1, 'Name 1' 2,
I have a problem. Right now, a file that was supposed to be tab-delimited
Suppose I have a table like: Tab(MyDate datetime null, MyIs bit null, ...) Then
Suppose , i have a tab activity consist of a TabHost. The TabHost contains
Suppose we have the name written in any none-latin letters - languages, like Arabic,
Given a text file that is supposed to contain 10 tab-delimited columns (i.e. 9
I have a WPF Menu and a Tab control. I would like the list
I have idea to implement my wpf windows like TabPages in tab control. It
Suppose I have a simple makefile like: hello: echo hello world bye: echo bye

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.