Hadoop 类Grep源代码注释
/**
* 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源代码注释的更多相关文章
- DevOps:怎么实现源代码注释和系统文档的自动化更新?
[编者按]计算机软件传统定义为:软件是计算机系统中与硬件相依存的另一部分,软件包括程序.数据及其相关文档的完整集合.然而在时下的开发中,文档的合规性往往被忽视的干干净净.本文由 Todd Waits ...
- Myeclipse中导入项目后java类中汉字注释出现乱码问题(已解决)
今天重装系统,安装了新的Myeclipse后,导入之前的项目后,,出现了乱码问题.乱码问题主要是java类中的注释,而jsp页面中汉字却完好如初: 右键项目,查看项目的编码格式,UTF-8,把java ...
- VS类自定义版权注释
对IDE快捷方式右键-属性-打开文件位置,找到..\Microsoft Visual Studio 10.0\Common7\IDE文件夹下的..\ItemTemplates\CSharp\Code\ ...
- 在Eclipse中设置Java类上面的注释(包含作者、日期等)
希望在Eclipse中,让Java类上面的注释像下面这样,改如何设置呢? 在Eclipse中,点击菜单中的Window-->Preferences,打开如下窗口:
- Microsoft源代码注释语言(SAL)提供设置批注
Microsoft源代码注释语言(SAL)提供设置批注可以使用描述的功能如何使用其参数,它对其假设并确保它使其在完成. 批注可标头文件 <sal.h>定义. Visual Studio C ...
- PHP类和函数注释大全
每次要用PHP的某个功能的时候,都要去查一下,于是决定将PHP所有类和函数都整理出来,加上注释 大致实现 将php.jar文件解压,取出目录stubs 将stubs中的所有php文件中的注释去掉,并做 ...
- idea中添加类和方法注释以及codeCheck
前言:在idea中我们添加类以及类的方法的注释很有必要,让其他人能够看懂这个类或者函数的作用是什么:为了在开发过程中检查自己的编程规范,可以通过codecheck工具进行自我检查和约束 一.在idea ...
- Eclipse给方法或者类添加自动注释
自动生成注释: 在团队开发中,注释是必不可少的,为了是自己的注释看起来更加优雅,注释的格式应该统一,我们可以使用Eclipse注释模板自动生成注释. 具体操作如下: 打开注释模板编辑窗口:Window ...
- idea 模版之自定义类与方法注释
idea 模版之自定义类与方法注释 很多公司都有要求的代码注释规范,我们每新建类或者方法的时候从新复制粘贴很麻烦,而且容易粘错. 当然自定义模板还可以用到很多地方,比如系统自带的 sout就是syst ...
随机推荐
- Java多线程——ThreadLocal类
一.概述 ThreadLocal是什么呢?其实ThreadLocal并非是一个线程的本地实现版本,它并不是一个Thread,而是threadlocalvariable(线程局部变量).也许把它命名 ...
- ASP.NET-FineUI开发实践-9(三)
1. TextChanged事件前台触发回发后台,接上文,先给TextBox1加上事件,看看是怎么生成出来的, 注意AutoPostBack="true",找源代码,f4多出了个 ...
- minus的用法
简单的说就是去同留异. MINUS 指令是运用在两个 SQL 语句上.它先找出第一个 SQL 语句所产生的结果,然后看这些结果有没有在第二个 SQL 语句的结果中.如果有的话,那这一笔资料就被去除,而 ...
- 解释DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci
解释DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci 在创建数据库的时候,经常用到一句:CREATE DATABASE `tpcms` DEFAUL ...
- (七)Angularjs - 控制器
控制器的作用 没有控制器/controller,我们没有地方定义业务模型 比如:ng-init指令.我们可以使用ng-init指令在scope对象上定义数据 <div ng-init=" ...
- MySQL Connector/Python 安装、测试
安装Connector/Python: # wget http://cdn.mysql.com/Downloads/Connector-Python/mysql-connector-pyth ...
- linux学习第一天(X window 及 语系查询设置)
前言: 在写这篇博文之前,我已经详细阅读了<鸟哥的Linux私房菜>,但是实践并不深入,只是单纯的为了了解常用的命令,扩展自己的知识广度.看过一遍感觉收获还是有的,但是并不是很精通.因此, ...
- 关于Jquery EasyUI中的DataGrid服务器端分页随记
一.关于DataGrid的分页和排序参数 对于分页参数不需要用户指定,程序在AJAX请求的时候会带上分页和排序需要的参数 每页显示条数:rows 当前页:page 排序字段:sort [multiS ...
- linux笔记2.21
命令dmesg显示本次内核启动信息 init是系统运行的第一个进程 Linux运行级别: 0 关机 1 单用户模式 2 不带网络的多用户模式 3 命令行多用户模式 4 未使用 5 ...
- js 音乐
define(function(require,exports,module){ var $music = document.getElementById('music'); var $music_m ...