Mapreduce算法四、key值和value值分别是组合值
来源:互联网 发布:js身份证号码格式 编辑:程序博客网 时间:2024/05/17 08:29
package CartsDemo;import java.util.HashSet;import java.util.Set;import org.apache.hadoop.conf.Configuration;import org.apache.hadoop.fs.Path;import org.apache.hadoop.io.LongWritable;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.lib.input.FileInputFormat;import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;public class TypeAndBrand {public static void main(String[] args) throws Exception { if(args.length!=2){ System.exit(0); } Job job = new Job(new Configuration(),"TypeAndBrand"); job.setJarByClass(TypeAndBrand.class); FileInputFormat.setInputPaths(job, new Path(args[0])); FileOutputFormat.setOutputPath(job, new Path(args[1])); job.setMapperClass(TypeAndBrandMap.class); job.setReducerClass(TypeAndBrandReduce.class); job.setMapOutputKeyClass(Text.class); job.setMapOutputValueClass(Text.class); job.setOutputKeyClass(Text.class); job.setOutputValueClass(Text.class); job.waitForCompletion(true);}public static class TypeAndBrandMap extends Mapper<LongWritable, Text, Text, Text>{ protected void map(LongWritable key, Text value, org.apache.hadoop.mapreduce.Mapper<LongWritable,Text,Text,Text>.Context context) throws java.io.IOException ,InterruptedException { String[] lines = value.toString().split("\t"); if(lines.length>7&&lines[7]!=null&&lines[8]!=null&&lines[7]!=""&&lines[8]!=""){ String brand = lines[7].trim(); String type = lines[8].trim(); if (lines.length>15&&lines[12]!=null&&lines[15]!=null&&lines[12]!=""&&lines[15]!="") { String engine = lines[12].trim(); String oil = lines[15].trim(); context.write(new Text(type+"-"+brand), new Text(engine+"-"+oil)); } } };}public static class TypeAndBrandReduce extends Reducer<Text, Text, Text, Text>{ protected void reduce(Text key, java.lang.Iterable<Text> values, org.apache.hadoop.mapreduce.Reducer<Text,Text,Text,Text>.Context context) throws java.io.IOException ,InterruptedException { Set<String > set = new HashSet<>(); for (Text value : values) { set.add(value.toString()); } context.write(key, new Text(set.toString())); };}}
0 0
- Mapreduce算法四、key值和value值分别是组合值
- MapReduce算法形式九:组合key或组合value
- Map分别按照Key和value排序
- hashMap分别获取所有key和value
- Map获取key值和value值
- 百度地图申请key和value值
- Map四种获取key和value值的方法,以及对map中的元素排序
- Map四种获取key和value值的方法,以及对map中的元素排序
- Map四种获取key和value值的方法,以及对map中的元素排序
- 对Map类分别按照Key,Value排序,返回值为List对象
- MapReduce之自定义Key和Value
- 在JavaScript中获取Map集合中的key和value值(前提是:既不知道key为什么值,也不知道value有哪些值)
- Map<Key,Value>基于Value值排序
- Spark中sortByKey和sortBy对(key,value)数据分别 根据key和value排序
- Spark中sortByKey和sortBy对(key,value)数据分别 根据key和value排序
- Map四种获取key和value值的方法,以及对map中的元素排序(转载)
- 分别根据key和value对HashMap进行排序
- java--TreeMap按key和value分别排序
- 学习笔记1(php基础)
- 怎么让手机网站自适应设备屏幕宽度?
- bind编译安装(精简版)
- 利用arcpy按字段值筛选要素工具
- ROS:使用ROS_arduino_bridge Stack
- Mapreduce算法四、key值和value值分别是组合值
- MyEclipse里面集成Tomcat
- 深复制和浅复制
- 【计算机视觉】OpenCV之GPU与OpenCL的相关内容说明
- 字符进行数值运算
- 2016-2017 CT S03E06: Codeforces Trainings Season 3 Episode 6 The Baguette Master
- 二叉树的链式实现
- 深度学习:Hinton_Science_Reducing the dimensionality of data with neural networks
- Cpp Concurrency In Action(读书笔记2)——线程间共享数据