Hadoop MapReduce 学习笔记(一) 序言和准备
? ?本博客属原创文章,转载请注明出处:http://guoyunsky.iteye.com/blog/1233707
? ?欢迎加入Hadoop超级群:?180941958
???????? 本博客已迁移到本人独立博客:http://www.yun5u.com/articles/hadoop-mapreduce-sql-1.html
?
???????? 下一篇:Hadoop MapReduce 学习笔记(二) 序言和准备 2
?
??????? 终于踏入了Hadoop的世界,先学习了Sqoop,然后MapReduce.这里结合MapReduce实现类似SQL的各种功能.如:max,min,order by,inner/left/right join group by等.但这里只是我的一个学习的过程,还有很多不足和错误.但我会步步深入不断改进,希望也能帮助到大家.同时今后也会不断跟进,比如读PIG/Hive的源码,看他们如何组织,如何写MapReduce.以及工作过程中一些实践经验和心得.毕竟这块资料还是比较少,尤其是系统性的.
? ? ? ?这里我先贴上几个准备类,用于生成测试数据.以及答个测试框架.
? ?? 首先贴上测试父类,具体请看注释:
?
package com.guoyun.hadoop.mapreduce.study;import org.slf4j.Logger;import org.slf4j.LoggerFactory;/** * MapReduce 测试父类 */public abstract class MyMapReduceTest { public static final Logger log=LoggerFactory.getLogger(MyMapReduceTest.class); public static final String DEFAULT_INPUT_PATH="testDatas/mapreduce/MRInput"; public static final String DEFAULT_OUTPUT_PATH="testDatas/mapreduce/MROutput"; public static final String NEW_LINE="\r"; public static final int DEFAULT_LENGTH=1000; protected String inputPath=DEFAULT_INPUT_PATH; // hadoop input protected String outputPath=DEFAULT_OUTPUT_PATH; // hadoop output protected boolean isGenerateDatas=false; // 是否生成测试数据 protected long maxValue=Long.MIN_VALUE; // 生成数的最大值,以便跟结果比较 protected long minValue=Long.MAX_VALUE; // 生成数的最小值,以便跟结果比较 public MyMapReduceTest(long dataLength) throws Exception { this(dataLength,DEFAULT_INPUT_PATH,DEFAULT_OUTPUT_PATH); } /** * 该构造方法不会自动生成数据 * @param outputPath */ public MyMapReduceTest(String outputPath) { this.outputPath=outputPath; } /** * 该构造方法不会自动生成数据,同时会重用input的输入数据 * @param outputPath */ public MyMapReduceTest(String inputPath,String outputPath) { this.inputPath=inputPath; this.outputPath=outputPath; } public MyMapReduceTest(long dataLength,String inputPath, String outputPath) throws Exception { this.inputPath = inputPath; this.outputPath = outputPath; isGenerateDatas=true; init(dataLength); } public String getInputPath() { return inputPath; } public void setInputPath(String inputPath) { this.inputPath = inputPath; } public String getOutputPath() { return outputPath; } public void setOutputPath(String outputPath) { this.outputPath = outputPath; } public long getMaxValue() { return maxValue; } public void setMaxValue(long maxValue) { this.maxValue = maxValue; } public long getMinValue() { return minValue; } public void setMinValue(long minValue) { this.minValue = minValue; } public boolean isGenerateDatas() { return isGenerateDatas; } /** * 初始化,根据设置,会自动生成测试数据 * * @param length * @throws Exception */ private void init(long length) throws Exception{ if(isGenerateDatas){ generateDatas(length); } } /** * 生成测试数据,写入inputPath. * 根据不同的测试需要,由子类完成 * * @param length * @throws Exception */ protected abstract void generateDatas(long length) throws Exception; }