Hadoop MapReduce 学习笔记(一) 序言和准备

本文分享了作者踏入Hadoop世界的学习历程,重点介绍了使用MapReduce实现类似SQL的功能,如max、min、orderby等,并提供了测试父类代码示例。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

终于踏入了Hadoop的世界,先学习了Sqoop,然后MapReduce.这里结合MapReduce实现类似SQL的各种功能.如:max,min,order by,inner/left/right join group by等.但这里只是我的一个学习的过程,还有很多不足和错误.但我会步步深入不断改进,希望也能帮助到大家.同时今后也会不断跟进,比如读PIG/Hive的源码,看他们如何组织,如何写MapReduce.以及工作过程中一些实践经验和心得.毕竟这块资料还是比较少,尤其是系统性的.

       这里我先贴上几个准备类,用于生成测试数据.以及答个测试框架.

     首先贴上测试父类,具体请看注释:

 
Java代码  收藏代码

    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;  
       
    } 

转载请注明出处:http://guoyunsky.iteye.com/blog/1233707


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值