List of usage examples for org.apache.hadoop.io IntWritable get
public int get()
From source file:Analysis.A3_Total_Users_By_Gender.User_Gender_Count_Reducer.java
public void reduce(Text key, Iterable<IntWritable> values, Context context) throws IOException, InterruptedException { int count = 0; for (IntWritable value : values) { count += value.get(); }// w w w . j a va 2 s . c o m result.set(count); // print gender and count context.write(key, result); }
From source file:Analysis.A4_High_Traffic_Countries.Top_10_Countries_by_User_Traffic_Combiner.java
public void reduce(Text key, Iterable<IntWritable> values, Context context) throws IOException, InterruptedException { int count = 0; for (IntWritable value : values) { count += value.get(); }// w w w .j a va 2s . c o m total.set(count); context.write(key, total); }
From source file:Analysis.A4_High_Traffic_Countries.Top_10_Countries_by_User_Traffic_Reducer.java
public void reduce(Text key, Iterable<IntWritable> values, Context context) throws IOException, InterruptedException { int count = 0; for (IntWritable value : values) { count += value.get(); }/*from w w w .ja v a 2s . co m*/ //add this country with its play count to tree map top10.put(count, key.toString()); // if map size has grown > 10 then remove first entry as tree map sorts in ascending order if (top10.size() > 20) { top10.remove(top10.lastKey()); } }
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();/*ww w. j a v a 2 s. co 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.A6_User_Differentiation_By_Age.Partition_Users_By_Age_Partitioner.java
@Override public int getPartition(IntWritable key, Text value, int numOfPartitions) { if (numOfPartitions == 0) return 0; if (key.get() >= 11 && key.get() <= 17) return 1; if (key.get() >= 18 && key.get() <= 25) return 2; if (key.get() >= 26 && key.get() <= 35) return 3; if (key.get() >= 36 && key.get() <= 49) return 4; if (key.get() >= 50 && key.get() <= 65) return 5; if (key.get() >= 66 && key.get() <= 80) return 6; if (key.get() >= 81 && key.get() <= 99) return 7; else/*from www.j a v a 2 s . c o m*/ return 0; }
From source file:Analysis.A8_Top_10_Most_Popular_Tracks.Top_10_Most_Popular_Tracks_Reducer.java
public void reduce(Text key, Iterable<IntWritable> values, Context context) throws IOException, InterruptedException { int totalUniquePlayCount = 0; // get count and add for (IntWritable uniqueCount : values) { totalUniquePlayCount += uniqueCount.get(); }/*from w ww.j a v a 2s . c o m*/ //add this track with its play count to tree map top10.put(totalUniquePlayCount, key.toString()); // if map size has grown > 10 then remove first entry as tree map sorts in ascending order if (top10.size() > 10) { top10.remove(top10.lastKey()); } }
From source file:ar.edu.ungs.garules.CensusJob.java
License:Apache License
/** * Toma la salida del reducer del file system distribuido y la carga en el mapa "ocurrencias" en memoria * @param conf//from w ww .j a va 2 s . c o m * @param path * @throws IOException */ @SuppressWarnings("deprecation") private static void llenarOcurrencias(Configuration conf, String path) throws IOException { FileSystem fs = new DistributedFileSystem( new InetSocketAddress(DEFAULT_FILE_SYSTEM_HOST, DEFAULT_FILE_SYSTEM_PORT), conf); SequenceFile.Reader reader = new SequenceFile.Reader(fs, new Path(path + "/part-r-00000"), conf); Text key = new Text(); IntWritable value = new IntWritable(); while (reader.next(key, value)) ocurrencias.put(key.toString(), value.get()); reader.close(); }
From source file:Assignment1_Wordcount.WordCount_Reducer.java
public void reduce(Text key, Iterable<IntWritable> values, Context context) throws IOException, InterruptedException { int sum = 0;/* w ww. j a v a2s . co m*/ for (IntWritable val : values) { sum += val.get(); } result.set(sum); context.write(key, result); }
From source file:Assignment2_P3_GenderMovieCount.GenderMovieRating_Reducer.java
public void reduce(Text key, Iterable<IntWritable> values, Context context) throws IOException, InterruptedException { int sum = 0;/*from w w w . java 2 s . c o m*/ for (IntWritable val : values) { sum += val.get(); } result.set(sum); context.write(key, result); }
From source file:Assignment2_P4_MovieRatingCount.MovieRating_Reducer.java
public void reduce(IntWritable key, Iterable<IntWritable> values, Context context) throws IOException, InterruptedException { int sum = 0;//from w w w.j av a2 s. c o m for (IntWritable val : values) { sum += val.get(); } result.set(sum); context.write(key, result); }