MapReduce 只有Map阶段,写出到pc端
来源:互联网 发布:创始于淘宝的女装品牌 编辑:程序博客网 时间:2024/06/10 22:55
package ProOrder2;import java.io.BufferedReader;import java.io.FileInputStream;import java.io.FileReader;import java.io.IOException;import java.io.InputStreamReader;import java.util.HashMap;import org.apache.hadoop.io.LongWritable;import org.apache.hadoop.io.NullWritable;import org.apache.hadoop.io.Text;import org.apache.hadoop.mapreduce.Mapper;public class ProOrdMapper2 extends Mapper<LongWritable, Text, Text, NullWritable>{ HashMap<String, String> map = new HashMap<String,String>(); @Override protected void setup(Context context) throws IOException, InterruptedException { BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream("E:/study/bigdata/hadoop/第8天/product/product.txt"))); String line=""; String pId=""; String pName=""; while((line=br.readLine())!=null){ String[] strs = line.split("\t"); pId = strs[0]; pName = strs[3]; map.put(pId, pName); } br.close(); } @Override protected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException { String[] split = value.toString().split("\t"); String orderId = split[2]; Text text = new Text(value + "\t" +map.get(orderId)); context.write(text, NullWritable.get()); }}
只有map阶段也是可以直接输出的
package ProOrder2;import java.io.IOException;import java.net.URI;import org.apache.hadoop.conf.Configuration;import org.apache.hadoop.fs.Path;import org.apache.hadoop.io.NullWritable;import org.apache.hadoop.io.Text;import org.apache.hadoop.mapreduce.Job;import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;public class ProOrdDriver2 { public static void main(String[] args) throws Exception { String path1=""; String path2=""; if(args.length==2){ path1 = args[0]; path2 = args[1]; }else{ return; } Configuration conf = new Configuration(); Job job = Job.getInstance(conf); job.setJarByClass(ProOrdDriver2.class); job.setMapperClass(ProOrdMapper2.class); job.setOutputKeyClass(Text.class); job.setOutputValueClass(NullWritable.class); FileInputFormat.setInputPaths(job, newPath(path1)); FileOutputFormat.setOutputPath(job, new Path(path2)); job.addCacheFile(new URI("file:///E:/study/bigdata/hadoop/第8天/product/product.txt")); boolean res = job.waitForCompletion(true); System.exit(res?0:1); }}
阅读全文
0 0
- MapReduce 只有Map阶段,写出到pc端
- mapreduce 的map shuffle reduce 阶段解析
- MapReduce阶段map的setup() 和cleanup()
- MapReduce算法形式六:只有Map独自作战
- MapReduce(十二): Map和Reduce阶段数据合并的处理
- MapReduce 图解流程超详细解答(1)-【map阶段】
- MapReduce 图解流程超详细解答(2)-【map阶段】
- MapReduce 图解流程超详细解答(1)-【map阶段】
- MapReduce 图解流程超详细解答(1)-【map阶段】
- 《从Paxos到ZooKeeper》读书笔记--两阶段提交 2PC
- MapReduce从分片输出到Map
- MapReduce作业Map阶段和Reduce阶段重要过程详述(Partitioner、Combiner、Shuffle三个阶段的解析)
- MapReduce的map端join
- hadoop执行mapreduce任务,能够map,不能reduce,Shuffle阶段报错
- MapReduce 编程 系列十一 Map阶段内部细节和调节参数
- MapReduce的Shuffle阶段
- 第二代MapReduce阶段解析
- MapReduce的shuffle阶段
- 采用ubuntu系统来安装tensorflow
- 堆结构和堆排序的Java实现
- 把项目备份到GitHub已存在的仓库
- MySQL带IN关键字的子查询
- HDU2389_Rain on your Parade_二分图匹配::Hopcroft-Carp模板题
- MapReduce 只有Map阶段,写出到pc端
- 简述document.write和 innerHTML的区别。
- python爬取csdn的博客内容
- 常用数据结构的详解(上)
- nodejs工具util.inherits与原生js的原型链继承实现与区别
- 安卓中机型适配问题
- python爬虫--urllib2和urllib区别
- mysql图形化工具使用记录
- 如何在CSDN的侧边栏添加人形时钟和可爱的小仓鼠