更新时间: 试题数量: 购买人数: 提供作者:

有效期: 个月

章节介绍: 共有个章节

收藏
搜索
题库预览
根据注释描述分别填写Main类,Map类和Reduce类对应java代码。要求将计算的结果保存在HDFS目录hdfs://192.168.44.128:9000/user/output/中。(24分) 其中ExamMapper类Mapper方法的代码实现(6分): package MapReduceExam; import ... public class ExamMapper extends Mapper<LongWritable, Text, Text, IntWritable >{ @Override protected void map(LongWritable key1,Text value1, Context context) throws IOException,InterruptedException{ String data = value1.toString(); // 将字符串以逗号为标记点进行分割,保存如字符串数组中 String[] words = data.split(","); int value4 = Integer.parseInt(words[4])*Integer.parseInt(words[5]); context.write(new Text(words[3]), new IntWritable(value4)); } } ExamReducer类Reducer方法的程序实现(6分): package MapReduceExam; import ... public class ExamReducer extends Reducer<Text, IntWritable, Text, IntWritable>{ @Override protected void reduce(Text key3,Iterable<IntWritable> value3, Context context) throws IOException,InterruptedException{ int price = 0; for (IntWritable value:value3) { price += value.get(); } context.write(key3, new IntWritable(price)); } } ExamMain类的main方法的程序实现(12分): package MapReduceExam; import ... public class ExamMain { public static void main( String[] args) throws Exception { // 创建一个job作业实例 Job job = Job.getInstance (new Configuration()); // 设置作业的启动类 job.setJarByClass (ExamMain.class); // 设置Map的类和输出类型 job.setMapperClass(ExamMapper.class); job.setMapOutputKeyClass(Text.class); job.setMapOutputValueClass(IntWritable.class); // 设置Reduce的类和输出类型 job.setReducerClass (ExamReducer.class); job.setOutputKeyClass (Text.class); job.setOutputValueClass (IntWritable.class); String path = "hdfs://192.168.44.128:9000/ExamData/"; FileInputFormat.setInputPaths(job,new Path(path +"SaleInfo.csv")); // 设置输出的唯一路径 FileOutputFormat.setOutputPath (job,new Path(path +"output")); // 执行job并等待处理过程结束 job.waitForCompletion (true); } }【缺少答案,请补充】
根据注释描述分别填写Main类,Map类和Reduce类对应java代码。要求将计算的结果保存在HDFS目录hdfs://192.168.44.128:9000/user/output/中。(24分) 其中ExamMapper类Mapper方法的代码实现(6分): package MapReduceExam; import ... public class ExamMapper extends Mapper<LongWritable, Text, Text, IntWritable >{ @Override protected void map(LongWritable key1,Text value1, Context context) throws IOException,InterruptedException{ String data = value1.toString(); // 将字符串以逗号为标记点进行分割,保存如字符串数组中 String[] words = data.split(","); context.write(words[4], new IntWritable(1)); } } ExamReducer类Reducer方法的程序实现(6分): package MapReduceExam; import ... public class ExamReducer extends Reducer<Text, IntWritable, Text, IntWritable>{ @Override protected void reduce(Text key3,Iterable<IntWritable> value3, Context context) throws IOException,InterruptedException{ int sum = 0; for (IntWritable value:value3) { sum += value.get(); } context.write(key3, new IntWritable(total)); } } ExamMain类的main方法的程序实现(12分): package MapReduceExam; import ... public class ExamMain { public static void main( String[] args) throws Exception { // 创建一个job作业实例 Job job = Job.getInstance (new Configuration()); // 设置作业的启动类 job.setJarByClass (ExamMain.class); // 设置Map的类和输入类型 job.setMapperClass(ExamMapper.class); job.setMapOutputKeyClass(Text.class); job.setMapOutputValueClass(IntWritable.class); // 设置reduce的类和输入类型 job.setReducerClass(ExamReducer.class); job.setOutputKeyClass(Text.class); job.setOutputValueClass (IntWritable.class); String path = "hdfs://192.168.44.128:9000/ExamData/"; ...(后续代码省略)
1