Example usage for org.apache.hadoop.io Text Text

List of usage examples for org.apache.hadoop.io Text Text

Introduction

In this page you can find the example usage for org.apache.hadoop.io Text Text.

Prototype

public Text(byte[] utf8) 

Source Link

Document

Construct from a byte array.

Usage

From source file:Analysis.A1_Total_Unique_Artists_on_Service.Distinct_Artist_Mapper.java

public void map(Object key, Text value, Context context) throws IOException, InterruptedException {
    // get artist info
    String[] artistInfo = value.toString().split("\t");

    // cleanup artist name by removing all whitespaces
    String aName = artistInfo[2] + "\t"; //.replaceAll("\\s+","");

    // extract artist name
    artistName = new Text(aName);

    context.write(artistName, NullWritable.get());
}

From source file:Analysis.A2_Top_20_Most_Popular_Artists.Top_20_Most_Popular_Artist_Mapper.java

public void map(Object key, Text value, Context context) throws IOException, InterruptedException {
    // get artist info
    String[] artistInfo = value.toString().split("\t");

    // cleanup artist name by removing all whitespaces
    String aName = artistInfo[2] + "\t"; //.replaceAll("\\s+","");

    // extract artist name
    artistName = new Text(aName);

    context.write(artistName, one);/*from w  w w.ja v  a  2 s .c  o m*/
}

From source file:Analysis.A2_Top_20_Most_Popular_Artists.Top_20_Most_Popular_Artist_Reducer.java

@Override
protected void cleanup(Context context) throws IOException, InterruptedException {
    for (Map.Entry<Integer, String> entry : top20.entrySet()) {

        //Integer key = entry.getKey();
        String value = entry.getValue().substring(0, 1).toUpperCase() + entry.getValue().substring(1);

        // print atop 20 artists
        context.write(NullWritable.get(), new Text(value));
    }/* w w  w  .j  a v  a2 s  .c  om*/
}

From source file:Analysis.A3_Total_Users_By_Gender.User_Gender_Count_Mapper.java

public void map(Object key, Text value, Context context) throws IOException, InterruptedException {
    // get user info
    String[] userInfo = value.toString().split("\t");
    String userGender = userInfo[1];

    // extract user gender
    gender = new Text(userGender);

    context.write(gender, one);//from  w  w  w  . java  2  s .c o m
}

From source file:Analysis.A4_High_Traffic_Countries.Top_10_Countries_by_User_Traffic_Mapper.java

public void map(Object key, Text value, Context context) throws IOException, InterruptedException {
    // get user info
    String[] userInfo = value.toString().split("\t");
    String cID = userInfo[3];//  ww  w .  ja  v a2s.  c o  m

    // extract artist name
    country = new Text(cID);

    context.write(country, one);
}

From source file:Analysis.A4_High_Traffic_Countries.Top_10_Countries_by_User_Traffic_Reducer.java

@Override
protected void cleanup(Context context) throws IOException, InterruptedException {
    for (Map.Entry<Integer, String> entry : top10.entrySet()) {

        IntWritable result = new IntWritable();

        //Integer key = entry.getKey();
        String value = entry.getValue().substring(0, 1).toUpperCase() + entry.getValue().substring(1);

        result.set(entry.getKey());/*www  .j av  a  2  s .c o  m*/

        // print top 10 counntries
        context.write(new Text(value), result);
    }
}

From source file:Analysis.A5_Min_Max_Median_Age_Top_Countries.Min_Max_Age_By_Country_Reducer.java

public void reduce(Text key, Iterable<IntWritable> values, Context context)
        throws IOException, InterruptedException {
    int minAge = 0;
    int maxAge = 0;
    int running_sum = 0;
    int running_count = 0;
    float median = 0;

    for (IntWritable value : values) {
        if (minAge <= 0 && value.get() > 10) {
            minAge = value.get();//  w w  w  .j av  a  2 s.c  o m
        }

        if (value.get() > 10 && value.get() < minAge) {
            minAge = value.get();
        }

        if (value.get() < 80 && value.get() > maxAge) {
            maxAge = value.get();
        }

        list.add(value.get());
        running_sum += value.get();
        running_count += one.get();
    }

    Collections.sort(list);

    // calculating median
    if (list.size() % 2 == 0) {
        median = (list.get((list.size() / 2) - 1) + list.get((list.size() / 2))) / 2;
    } else {
        median = list.get((list.size() / 2));
    }

    String op = String.valueOf(minAge) + "\t" + String.valueOf(median) + "\t" + String.valueOf(maxAge);
    Text out = new Text(op);

    context.write(key, out);

}

From source file:Analysis.A7_Total_Signups_By_Year.Total_Signup_by_Year_Mapper.java

public void map(Object key, Text value, Context context) throws IOException, InterruptedException {
    // get user info
    String[] userInfo = value.toString().split("\t");
    String signupDate = userInfo[4].trim();
    String signupYear = signupDate.split(",")[1];

    // extract signup year
    year = new Text(signupYear);

    context.write(year, one);//from  w w  w .  j av a 2  s  .com
}

From source file:Analysis.A8_Top_10_Most_Popular_Tracks.Top_10_Most_Popular_Tracks_Mapper.java

public void map(Object key, Text value, Context context) throws IOException, InterruptedException {
    // get artist info
    String[] trackInfo = value.toString().split("\t");

    String tName = trackInfo[5].trim();

    if (!tName.equals("[Untitled]") && !tName.equals("Untitled")) {
        // extract artist name
        trackName = new Text(tName);
        context.write(trackName, one);//from   w  w w .jav a  2  s  .c o m
    }
}

From source file:Analysis.A8_Top_10_Most_Popular_Tracks.Top_10_Most_Popular_Tracks_Reducer.java

@Override
protected void cleanup(Context context) throws IOException, InterruptedException {
    for (Map.Entry<Integer, String> entry : top10.entrySet()) {

        //Integer key = entry.getKey();
        String value = entry.getValue().substring(0, 1).toUpperCase() + entry.getValue().substring(1);

        // print top 10 tracks
        context.write(NullWritable.get(), new Text(value));
    }/*from w  ww .ja  v a  2 s. c o m*/
}