From 955ff6ca750a59d2cfa1dcb92c3baa5da34b55da Mon Sep 17 00:00:00 2001 From: Leonardo Pizarro <lepizarr@inf.utfsm.cl> Date: Sun, 18 Jun 2017 21:20:50 -0400 Subject: [PATCH] works with no combiner --- src/org/mdp/hadoop/cli/ActorsInMovie.java | 53 +++++++++++++++++++---- 1 file changed, 45 insertions(+), 8 deletions(-) diff --git a/src/org/mdp/hadoop/cli/ActorsInMovie.java b/src/org/mdp/hadoop/cli/ActorsInMovie.java index 6697312..7b0d1f8 100644 --- a/src/org/mdp/hadoop/cli/ActorsInMovie.java +++ b/src/org/mdp/hadoop/cli/ActorsInMovie.java @@ -1,6 +1,9 @@ package org.mdp.hadoop.cli; import java.io.IOException; +//import java.util.ArrayList; +//import java.util.HashMap; +import java.util.HashMap; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.fs.Path; @@ -8,6 +11,7 @@ import org.apache.hadoop.io.Text; import org.apache.hadoop.mapreduce.Job; import org.apache.hadoop.mapreduce.Mapper; import org.apache.hadoop.mapreduce.Reducer; +//import org.apache.hadoop.mapreduce.Reducer.Context; import org.apache.hadoop.mapreduce.lib.input.MultipleInputs; import org.apache.hadoop.mapreduce.lib.input.TextInputFormat; import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat; @@ -79,18 +83,51 @@ public class ActorsInMovie { /** * @throws InterruptedException */ - + private HashMap< String, String > map = new HashMap< String, String >() ; +// private ArrayList<String> store ; +// private String tmp = ""; +// private String year = ""; + @Override public void reduce(Text key, Iterable<Text> values, Context output) throws IOException, InterruptedException { - String tmp = "" ; - // Group all actors involved in the movie and write to ouput - for( Text value: values ) { - tmp += value + "#!!#"; +// store = new ArrayList<String>(); + +// The input is the year rating,movie_title#Type + for( Text value: values ) { +// store.add(value.toString()); + if ( map.containsKey( key.toString() ) ){ + map.put( key.toString(), map.get(key.toString()) + "-" + value.toString() ); + } + else { + map.put( key.toString(), value.toString() ); + } } - output.write(key, new Text( tmp ) ); +// output.write( key , new Text ( tmp + year ) ); +// A Picture of Katherine Mansfield#-#Life Is the Only Cure for Life (#1.1)#S [[1973], [Aitchison, PeggyF]] +// for ( int i = 0; i < store.size(); i++) { +// // if entry exists, extend value of map +// if ( map.containsKey( key ) ){ +// map.put( key.toString(), map.get(key) + "-" + store.get(i) ); +// } +// else { +// map.put( key.toString(), store.get(i) ); +// } +// } + } + + @Override + protected void cleanup(Context output) throws IOException, InterruptedException{ + + for ( String key: map.keySet()) { +// if ( map.get(key).matches(".*[\\d]{4}[-]{1}.*") ){ + if ( map.get(key).contains("18") || map.get(key).contains("19") || map.get(key).contains("20") ){ + output.write( new Text (key) , new Text ( map.get(key) ) ); +// A Picture of Katherine Mansfield#-#Life Is the Only Cure for Life (#1.1)#S 1973-Aitchison, PeggyF + } + } } } @@ -119,9 +156,9 @@ public class ActorsInMovie { job.setOutputValueClass(Text.class); // job.setMapperClass( ActorsMapper.class ); - job.setCombinerClass( ActorsReducer.class ); +// job.setCombinerClass( ActorsReducer.class ); job.setReducerClass( ActorsReducer.class ); - job.setNumReduceTasks(0); +// job.setNumReduceTasks(0); job.setJarByClass( ActorsInMovie.class ); job.waitForCompletion(true); -- GitLab