/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.tdxx.hadoop.example; import java.util.Random; import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.conf.Configured;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapred.*;
import org.apache.hadoop.mapred.lib.*;
import org.apache.hadoop.util.Tool;
import org.apache.hadoop.util.ToolRunner; /**
* 从input中提取与表达式相符的单词并计算词频
*
* 继承自配置基类Configured,并扩展接口Tool
* Configured类中有一个变量conf用于存储配置文件
* Tool中只有一个方法需要实现
* int run(String [] args)用于运行输入参数
* hadoop jar Grep.jar /user/hadoop/20130704/grep.txt /user/hadoop/output/ 'aaa.*'
* hadoop jar Grep.jar /user/hadoop/20130704/grep.txt /user/hadoop/output/ '[a-z.]+'
*/
public class Grep extends Configured implements Tool {
// singleton
private Grep() {
} public int run(String[] args) throws Exception {
if (args.length < 3) {
System.out.println("Grep <inDir> <outDir> <regex> [<group>]");
ToolRunner.printGenericCommandUsage(System.out);
return -1;
} Path tempDir = new Path("grep-temp-"
+ Integer.toString(new Random().nextInt(Integer.MAX_VALUE))); //创建job
JobConf grepJob = new JobConf(getConf(), Grep.class); try {
//job命名
grepJob.setJobName("grep-search"); //设置job的输入路径
FileInputFormat.setInputPaths(grepJob, args[0]); //设置Mapper类
grepJob.setMapperClass(RegexMapper.class); grepJob.set("mapred.mapper.regex", args[2]);
if (args.length == 4)
grepJob.set("mapred.mapper.regex.group", args[3]); //设置Combiner类
grepJob.setCombinerClass(LongSumReducer.class); //设置Reducer类
grepJob.setReducerClass(LongSumReducer.class); //设置输出路径
FileOutputFormat.setOutputPath(grepJob, tempDir); //设置输出格式
grepJob.setOutputFormat(SequenceFileOutputFormat.class); //设置输出键的类
grepJob.setOutputKeyClass(Text.class); //设置输出值的类
grepJob.setOutputValueClass(LongWritable.class); //运行
JobClient.runJob(grepJob); JobConf sortJob = new JobConf(getConf(), Grep.class);
sortJob.setJobName("grep-sort"); FileInputFormat.setInputPaths(sortJob, tempDir);
sortJob.setInputFormat(SequenceFileInputFormat.class); sortJob.setMapperClass(InverseMapper.class); sortJob.setNumReduceTasks(1); // write a single file
FileOutputFormat.setOutputPath(sortJob, new Path(args[1]));
sortJob.setOutputKeyComparatorClass // sort by decreasing freq
(LongWritable.DecreasingComparator.class); JobClient.runJob(sortJob);
} finally {
FileSystem.get(grepJob).delete(tempDir, true);
}
return 0;
} public static void main(String[] args) throws Exception {
int res = ToolRunner.run(new Configuration(), new Grep(), args);
System.exit(res);
} }

Hadoop 类Grep源代码注释的更多相关文章

  1. DevOps:怎么实现源代码注释和系统文档的自动化更新?

    [编者按]计算机软件传统定义为:软件是计算机系统中与硬件相依存的另一部分,软件包括程序.数据及其相关文档的完整集合.然而在时下的开发中,文档的合规性往往被忽视的干干净净.本文由 Todd Waits ...

  2. Myeclipse中导入项目后java类中汉字注释出现乱码问题(已解决)

    今天重装系统,安装了新的Myeclipse后,导入之前的项目后,,出现了乱码问题.乱码问题主要是java类中的注释,而jsp页面中汉字却完好如初: 右键项目,查看项目的编码格式,UTF-8,把java ...

  3. VS类自定义版权注释

    对IDE快捷方式右键-属性-打开文件位置,找到..\Microsoft Visual Studio 10.0\Common7\IDE文件夹下的..\ItemTemplates\CSharp\Code\ ...

  4. 在Eclipse中设置Java类上面的注释(包含作者、日期等)

    希望在Eclipse中,让Java类上面的注释像下面这样,改如何设置呢? 在Eclipse中,点击菜单中的Window-->Preferences,打开如下窗口:

  5. Microsoft源代码注释语言(SAL)提供设置批注

    Microsoft源代码注释语言(SAL)提供设置批注可以使用描述的功能如何使用其参数,它对其假设并确保它使其在完成. 批注可标头文件 <sal.h>定义. Visual Studio C ...

  6. PHP类和函数注释大全

    每次要用PHP的某个功能的时候,都要去查一下,于是决定将PHP所有类和函数都整理出来,加上注释 大致实现 将php.jar文件解压,取出目录stubs 将stubs中的所有php文件中的注释去掉,并做 ...

  7. idea中添加类和方法注释以及codeCheck

    前言:在idea中我们添加类以及类的方法的注释很有必要,让其他人能够看懂这个类或者函数的作用是什么:为了在开发过程中检查自己的编程规范,可以通过codecheck工具进行自我检查和约束 一.在idea ...

  8. Eclipse给方法或者类添加自动注释

    自动生成注释: 在团队开发中,注释是必不可少的,为了是自己的注释看起来更加优雅,注释的格式应该统一,我们可以使用Eclipse注释模板自动生成注释. 具体操作如下: 打开注释模板编辑窗口:Window ...

  9. idea 模版之自定义类与方法注释

    idea 模版之自定义类与方法注释 很多公司都有要求的代码注释规范,我们每新建类或者方法的时候从新复制粘贴很麻烦,而且容易粘错. 当然自定义模板还可以用到很多地方,比如系统自带的 sout就是syst ...

随机推荐

  1. WIN7 64位上 MYSQL的ODBC一些个人理解

    最近电脑中毒了,无奈之下把32位的xp换成了64位的win7,无聊耗时的搭完开发环境,装了vs6.0(忽略掉一切的不兼容),装完64位的mysql(“mysql-5.6.10-winx64.zip”) ...

  2. Myeclipse+Tomcat安装与配置

    一: Myeclipse安装很简单,没什么可说的,下面说一下怎么把英文版的Myeclipse汉化的问题 1.把汉化包解压,将解压后的“language”文件夹,放入Myeclipse\common文件 ...

  3. .net面试总结

    一. hr 为人处事 工作中遇到问题:沟通很重要 离职原因:公司倒闭 二. ISAPI Internet Server Application Program Interface 三. http状态码 ...

  4. java rmi 小记

    最近在搞Quartz任务监控管理,碰到了jmx,后来发现Quartz对jmx的支持不是很好,介绍的文档也比较少,另外Quartz可以很方便的支持rmi于是就看了一下rmi.下面把写的一些测试小例子附上 ...

  5. Ubuntu小私房(4)--Linux系统目录结构

    Linux目录结构是Linux学习者必须了解的知识,Linux的目录与Windows又有很大的不同,所以搞清楚Linux目录结构是关键. Linux文件类型 (部分转自ChinaBytel) linu ...

  6. mongodb安装服务

    一.准备工作 1:下载:  http://www.mongodb.org/downloads 2:解压到ZIP到 D:\Mongodb   ,在此目录下再建立2个目录  D:\Mongodb\db和D ...

  7. ubuntu增加工作分区(workspace)命令

    dconf write  /org/compiz/profiles/unity/plugins/core/hsize 3 dconf write  /org/compiz/profiles/unity ...

  8. SQL中对日期进行模糊查询的方法

    在我们通过SQL语句对数据库中的数据进行查询时,难免会遇到针对datetime的查询,但是因为一般情况下,输入的时间条件为年月日,所以,这种情况下,我们就要进行一下模糊查询,首先,摒弃一种投机取巧的方 ...

  9. DEDE提高生成HTmL的速度

    1.找到include/inc/inc_fun_SpGetArcList.php打开之.   2.查找以下代码:   for($i=0;$i<$ridnum;$i++){     if($tps ...

  10. 游戏算法中lua脚本详解

    此外,函数本身也是一个变量,比如: dp@dp:~ % cat test.lua local mylen={} mylen.len3=function (x,y,z) return math.sqrt ...