List of usage examples for org.apache.hadoop.io Text toString
@Override
public String toString()
From source file:Analysis.A5_Min_Max_Median_Age_Top_Countries.Min_Max_Age_By_Country_Mapper.java
public void map(Object key, Text value, Context context) throws IOException, InterruptedException { // get user info String[] userInfo = value.toString().split("\t"); String userCountry = userInfo[0].trim(); String userAge = userInfo[3].trim(); if (!userAge.trim().equals("")) { country.set(userCountry);//from w w w .ja v a 2 s.c om age.set(Integer.parseInt(userAge)); context.write(country, age); } // else{ // count++; // System.out.println("Total count " + count); // } }
From source file:Analysis.A6_User_Differentiation_By_Age.Partition_Users_By_Age_Mapper.java
public void map(Object key, Text value, Context context) throws IOException, InterruptedException { // get user info String[] userInfo = value.toString().split("\t"); String userAge = userInfo[2].trim(); if (!userAge.equals("")) { age.set(Integer.parseInt(userAge)); context.write(age, value);//from w w w .ja v a 2 s . c o m } }
From source file:Analysis.A6_User_Differentiation_By_Age.Partition_Users_By_Age_Reducer.java
public void reduce(Text key, Iterable<Text> values, Context context) throws IOException, InterruptedException { for (Text value : values) { multipleOutputs.write("ageBins", value, NullWritable.get(), key.toString()); }/*from w w w . java 2 s. co m*/ }
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 ww w . ja va2 s . c om }
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 ww .j ava2s .com*/ } }
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(); }/*w ww. jav a 2 s. com*/ //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:Analysis.A9_Max_Activity_By_Time_of_Day.Most_Listens_By_Time_of_Day_Mapper.java
public void map(Object key, Text value, Context context) throws IOException, InterruptedException { // get user info String[] userInfo = value.toString().split("\t"); String playTime = userInfo[1].trim(); Calendar cal = Calendar.getInstance(); try {//from w w w . ja v a 2s . co m if (playTime.equals("")) { context.getCounter(HOUR_COUNTER_GROUP, NULL_OR_EMPTY).increment(1); } else { cal.setTime(fmt.parse(playTime)); createHour.set(cal.get(Calendar.HOUR_OF_DAY)); if (hours.contains(createHour.toString())) { context.getCounter(HOUR_COUNTER_GROUP, createHour.toString()).increment(1); } } } catch (ParseException e) { e.printStackTrace(); } }
From source file:analysis3.crimeScoreMapper.java
public void map(LongWritable key, Text value, OutputCollector<Text, IntWritable> output, Reporter reporter) throws IOException { StringTokenizer tokenizer = new StringTokenizer(value.toString(), ","); if (tokenizer.countTokens() != 0) { String[] data = new String[tokenizer.countTokens()]; int i = 0; while (tokenizer.hasMoreTokens()) { data[i] = tokenizer.nextToken(); i++;// w ww. ja v a2 s . c o m } String type = data[2]; type = type.trim(); int weight = 0; if (type.equalsIgnoreCase("arson")) { weight = 2; } else if (type.equalsIgnoreCase("theft")) { weight = 3; } else if (type.equalsIgnoreCase("assault")) { weight = 2; } else if (type.equalsIgnoreCase("battery")) { weight = 4; } else if (type.equalsIgnoreCase("robbery")) { weight = 3; } else if (type.equalsIgnoreCase("burglary")) { weight = 3; } else if (type.equalsIgnoreCase("gambling")) { weight = 1; } else if (type.equalsIgnoreCase("homicide")) { weight = 4; } else if (type.equalsIgnoreCase("stalking")) { weight = 1; } else if (type.equalsIgnoreCase("narcotics")) { weight = 2; } else if (type.equalsIgnoreCase("obscenity")) { weight = 1; } else if (type.equalsIgnoreCase("kidnapping")) { weight = 3; } else if (type.equalsIgnoreCase("sex offense")) { weight = 3; } else if (type.equalsIgnoreCase("intimidation")) { weight = 2; } else if (type.equalsIgnoreCase("non - criminal")) { weight = 1; } else if (type.equalsIgnoreCase("prostitution")) { weight = 2; } else if (type.equalsIgnoreCase("other offense")) { weight = 1; } else if (type.equalsIgnoreCase("non-criminal")) { weight = 1; } else if (type.equalsIgnoreCase("criminal damage")) { weight = 2; } else if (type.equalsIgnoreCase("public indecency")) { weight = 2; } else if (type.equalsIgnoreCase("criminal trespass")) { weight = 2; } else if (type.equalsIgnoreCase("human trafficking")) { weight = 3; } else if (type.equalsIgnoreCase("weapons violation")) { weight = 2; } else if (type.equalsIgnoreCase("deceptive practice")) { weight = 2; } else if (type.equalsIgnoreCase("crim sexual assault")) { weight = 4; } else if (type.equalsIgnoreCase("motor vehicle theft")) { weight = 2; } else if (type.equalsIgnoreCase("liquor law violation")) { weight = 1; } else if (type.equalsIgnoreCase("public peace violation")) { weight = 1; } else if (type.equalsIgnoreCase("other narcotic violation")) { weight = 1; } else if (type.equalsIgnoreCase("offense involving children")) { weight = 3; } else if (type.equalsIgnoreCase("interference with public officer")) { weight = 1; } else if (type.equalsIgnoreCase("concealed carry license violation")) { weight = 2; } if (data[3].trim().startsWith("60")) output.collect(new Text(data[3].trim()), new IntWritable(weight)); else output.collect(new Text(data[4].trim() + "," + data[3].trim()), new IntWritable(weight)); } else { output.collect(new Text("ProBLEMMMMMMMMMMMMMMMMMMMMM"), new IntWritable(1)); } }
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/* w ww . j ava 2 s.c om*/ * @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.WordSort.java
License:Apache License
public int getPartition(Text key, IntWritable value, int numReducers) { int A = Character.getNumericValue('a'); int Z = Character.getNumericValue('z'); int R = Z - A + 1; int C = R / numReducers; char flet = key.toString().charAt(0); int F = Character.getNumericValue(flet) - A; return (F / C); }