- 浏览: 113098 次
- 性别:
- 来自: 北京
文章分类
- 全部博客 (109)
- hive (5)
- web (1)
- spring (7)
- struts2 (1)
- s2sh (2)
- mysql (3)
- hadoop (31)
- hbase (6)
- java (8)
- ubuntu (8)
- pig (2)
- Interview (2)
- zookeeper (1)
- system (1)
- 遥控 (1)
- linux (3)
- myeclipse (2)
- Oracle (1)
- redis (9)
- ibatis (2)
- 架构 (2)
- 解析xml (1)
- autoProxy (0)
- jedis (6)
- http://www.infoq.com/cn/articles/tq-redis-copy-build-scalable-cluster (1)
- xmemcached (1)
- 图片服务器 (1)
- 对象池 (0)
- netty (1)
最新评论
-
laoma102:
已经不好使了,能找到最新的吗
spring官方文档 -
di1984HIT:
不错,。不错~
pig安装
http://www.easyigloo.org/?p=1145
很多时候想要测试hadoop上的一个想法,要求快速创建并运行任务。每个任务包含了至少3个组件。
Mapper类
Reducer类
Wrapper类
下面的代码用以产生空模板,只是将变量替换成自己的类名
MAPPER
-----------------------------------------------------------------------------------------------------------------------------------
MAPPER
-----------------------------------------------------------------------------------------------------------------------------------
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.mapreduce.Mapper;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import java.io.IOException;
/* In case you are using Multiple outputs */
//import org.apache.hadoop.io.NullWritable;
//import org.apache.hadoop.mapreduce.lib.output.MultipleOutputs;
public class Mapper extends Mapper {
private Configuration conf;
private Text outputKey = new Text();
private Text outputValue = new Text();
private String line = null;
/* In case you are using Multiple outputs */
//private NullWritable outputValue = NullWritable.get();
//private MultipleOutputs contextMulti = null;
@Override
public void setup(Mapper.Context context) {
this.conf = context.getConfiguration();
/* In case you are using Multiple outputs */
//contextMulti = new MultipleOutputs(context);
}
@Override
public void map(LongWritable key, Text values, Context context)
throws IOException, InterruptedException {
}
@Override
public void cleanup (Mapper.Context context)throws IOException, InterruptedException {
/* In case you are using Multiple outputs */
//contextMulti.close();
}
}
-----------------------------------------------------------------------------------------------------------------------------------
REDUCER
-----------------------------------------------------------------------------------------------------------------------------------
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Reducer;
import java.io.IOException;
/* In case you are using Multiple outputs */
//import org.apache.hadoop.io.NullWritable;
//import org.apache.hadoop.mapreduce.lib.output.MultipleOutputs;
public class Reducer extends Reducer {
private Configuration conf;
private Text outputKey = new Text();
private Text outputValue = new Text();
private String line = null;
/* In case you are using Multiple outputs */
//private NullWritable outputValue = NullWritable.get();
//private MultipleOutputs contextMulti = null;
@Override
public void setup(Reducer.Context context) {
this.conf = context.getConfiguration();
/* In case you are using Multiple outputs */
//contextMulti = new MultipleOutputs(context);
}
@Override
public void reduce(Text key, Iterable values, Context context)
throws IOException, InterruptedException {
}
@Override
public void cleanup(Reducer.Context context) {
/* In case you are using Multiple outputs */
//contextMulti.close();
}
}
-----------------------------------------------------------------------------------------------------------------------------------
WRAPPER
这个类用到下面两个类
https://sites.google.com/site/hadoopandhive/home/ExtendedFileUtil.java?attredirects=0&d=1
https://sites.google.com/site/hadoopandhive/home/StringUtil.java?attredirects=0&d=1
-----------------------------------------------------------------------------------------------------------------------------------
import StringUtil;
import ExtendedFileUtil;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.conf.Configured;
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.TextInputFormat;
import org.apache.hadoop.mapreduce.lib.output.TextOutputFormat;
import org.apache.hadoop.util.Tool;
import org.apache.hadoop.util.ToolRunner;
import java.io.IOException;
import java.text.ParseException;
public class extends Configured implements Tool, Constants {
private Configuration conf = null;
private Job job = null;
private String inputDirList = null;
private String outputDir = null;
private String[] filesToProcess = null;
private int totalReducers = 0;
private int jobRes = 0;
private ExtendedFileUtil fileUtil = new ExtendedFileUtil();
public static void main(String[] args) throws Exception {
ob = new ();
int jobRes = ToolRunner.run(ob, args);
}
public int run(String[] args)
throws ClassNotFoundException, IOException, InterruptedException, ParseException {
jobRes = readCmdArgs(args);
if (jobRes == 0) {
jobRes = readConfig();
}
if (jobRes == 0) {
jobRes = runMrJob();
}
return jobRes;
}
private int readCmdArgs(String[] args) {
if (args.length == 2) {
inputDirList = args[0];
outputDir = args[1];
} else {
printUsage();
System.exit(1);
}
return 0;
}
private int readConfig() throws IOException, InterruptedException, ClassNotFoundException {
conf = new Configuration();
//conf.set("SET_NEW_CONFIG_NAME", SET_NEW_CONFIG_VALUE);
job = new Job(conf);
if ((job.getJar() == null) || (job.getJar() == "")) {
job.setJarByClass(.class);
}
return 0;
}
private int runMrJob()
throws IOException, InterruptedException, ClassNotFoundException {
filesToProcess = fileUtil.getFilesOnly(inputDirList, true);
job.setJobName("");
TextInputFormat.addInputPaths(job, StringUtil.arrayToString(filesToProcess, ","));
TextOutputFormat.setOutputPath(job, new Path(outputDir));
System.out.println("Input Dir: " + inputDirList);
System.out.println("Output Dir: " + outputDir);
job.setMapperClass(Mapper.class);
job.setMapOutputKeyClass(Text.class);
job.setMapOutputValueClass(Text.class);
job.setReducerClass(Reducer.class);
job.setOutputKeyClass(Text.class);
job.setOutputValueClass(Text.class);
totalReducers = Math.round((fileUtil.size(inputDirList) / 134217728) * 0.1F);
totalReducers = Math.max(totalReducers, 1);
job.setNumReduceTasks(totalReducers );
deleteOutputDirectory(outputDir);
jobRes = job.waitForCompletion(true) ? 0 : 1;
deleteLogsDirectory();
fileUtil.removeAllZeroByteFiles(outputDir);
return 0;
}
private int deleteOutputDirectory(String outputDir) throws IOException {
fileUtil.removeHdfsPath(new Path(outputDir).toString());
return 0;
}
private int printUsage() {
System.out.println("USAGE:
");
return 0;
}
private int deleteLogsDirectory()
throws IOException {
Path outputLogPath = new Path(new Path(outputDir).toString() + "/" + "_logs");
fileUtil.removeHdfsPath(outputLogPath.toString());
return 0;
}
}
很多时候想要测试hadoop上的一个想法,要求快速创建并运行任务。每个任务包含了至少3个组件。
Mapper类
Reducer类
Wrapper类
下面的代码用以产生空模板,只是将变量替换成自己的类名
MAPPER
-----------------------------------------------------------------------------------------------------------------------------------
MAPPER
-----------------------------------------------------------------------------------------------------------------------------------
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.mapreduce.Mapper;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import java.io.IOException;
/* In case you are using Multiple outputs */
//import org.apache.hadoop.io.NullWritable;
//import org.apache.hadoop.mapreduce.lib.output.MultipleOutputs;
public class Mapper extends Mapper {
private Configuration conf;
private Text outputKey = new Text();
private Text outputValue = new Text();
private String line = null;
/* In case you are using Multiple outputs */
//private NullWritable outputValue = NullWritable.get();
//private MultipleOutputs contextMulti = null;
@Override
public void setup(Mapper.Context context) {
this.conf = context.getConfiguration();
/* In case you are using Multiple outputs */
//contextMulti = new MultipleOutputs(context);
}
@Override
public void map(LongWritable key, Text values, Context context)
throws IOException, InterruptedException {
}
@Override
public void cleanup (Mapper.Context context)throws IOException, InterruptedException {
/* In case you are using Multiple outputs */
//contextMulti.close();
}
}
-----------------------------------------------------------------------------------------------------------------------------------
REDUCER
-----------------------------------------------------------------------------------------------------------------------------------
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Reducer;
import java.io.IOException;
/* In case you are using Multiple outputs */
//import org.apache.hadoop.io.NullWritable;
//import org.apache.hadoop.mapreduce.lib.output.MultipleOutputs;
public class Reducer extends Reducer {
private Configuration conf;
private Text outputKey = new Text();
private Text outputValue = new Text();
private String line = null;
/* In case you are using Multiple outputs */
//private NullWritable outputValue = NullWritable.get();
//private MultipleOutputs contextMulti = null;
@Override
public void setup(Reducer.Context context) {
this.conf = context.getConfiguration();
/* In case you are using Multiple outputs */
//contextMulti = new MultipleOutputs(context);
}
@Override
public void reduce(Text key, Iterable values, Context context)
throws IOException, InterruptedException {
}
@Override
public void cleanup(Reducer.Context context) {
/* In case you are using Multiple outputs */
//contextMulti.close();
}
}
-----------------------------------------------------------------------------------------------------------------------------------
WRAPPER
这个类用到下面两个类
https://sites.google.com/site/hadoopandhive/home/ExtendedFileUtil.java?attredirects=0&d=1
https://sites.google.com/site/hadoopandhive/home/StringUtil.java?attredirects=0&d=1
-----------------------------------------------------------------------------------------------------------------------------------
import StringUtil;
import ExtendedFileUtil;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.conf.Configured;
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.TextInputFormat;
import org.apache.hadoop.mapreduce.lib.output.TextOutputFormat;
import org.apache.hadoop.util.Tool;
import org.apache.hadoop.util.ToolRunner;
import java.io.IOException;
import java.text.ParseException;
public class extends Configured implements Tool, Constants {
private Configuration conf = null;
private Job job = null;
private String inputDirList = null;
private String outputDir = null;
private String[] filesToProcess = null;
private int totalReducers = 0;
private int jobRes = 0;
private ExtendedFileUtil fileUtil = new ExtendedFileUtil();
public static void main(String[] args) throws Exception {
ob = new ();
int jobRes = ToolRunner.run(ob, args);
}
public int run(String[] args)
throws ClassNotFoundException, IOException, InterruptedException, ParseException {
jobRes = readCmdArgs(args);
if (jobRes == 0) {
jobRes = readConfig();
}
if (jobRes == 0) {
jobRes = runMrJob();
}
return jobRes;
}
private int readCmdArgs(String[] args) {
if (args.length == 2) {
inputDirList = args[0];
outputDir = args[1];
} else {
printUsage();
System.exit(1);
}
return 0;
}
private int readConfig() throws IOException, InterruptedException, ClassNotFoundException {
conf = new Configuration();
//conf.set("SET_NEW_CONFIG_NAME", SET_NEW_CONFIG_VALUE);
job = new Job(conf);
if ((job.getJar() == null) || (job.getJar() == "")) {
job.setJarByClass(.class);
}
return 0;
}
private int runMrJob()
throws IOException, InterruptedException, ClassNotFoundException {
filesToProcess = fileUtil.getFilesOnly(inputDirList, true);
job.setJobName("");
TextInputFormat.addInputPaths(job, StringUtil.arrayToString(filesToProcess, ","));
TextOutputFormat.setOutputPath(job, new Path(outputDir));
System.out.println("Input Dir: " + inputDirList);
System.out.println("Output Dir: " + outputDir);
job.setMapperClass(Mapper.class);
job.setMapOutputKeyClass(Text.class);
job.setMapOutputValueClass(Text.class);
job.setReducerClass(Reducer.class);
job.setOutputKeyClass(Text.class);
job.setOutputValueClass(Text.class);
totalReducers = Math.round((fileUtil.size(inputDirList) / 134217728) * 0.1F);
totalReducers = Math.max(totalReducers, 1);
job.setNumReduceTasks(totalReducers );
deleteOutputDirectory(outputDir);
jobRes = job.waitForCompletion(true) ? 0 : 1;
deleteLogsDirectory();
fileUtil.removeAllZeroByteFiles(outputDir);
return 0;
}
private int deleteOutputDirectory(String outputDir) throws IOException {
fileUtil.removeHdfsPath(new Path(outputDir).toString());
return 0;
}
private int printUsage() {
System.out.println("USAGE:
");
return 0;
}
private int deleteLogsDirectory()
throws IOException {
Path outputLogPath = new Path(new Path(outputDir).toString() + "/" + "_logs");
fileUtil.removeHdfsPath(outputLogPath.toString());
return 0;
}
}
发表评论
-
mapreduce Bet
2012-04-11 15:00 918import java.io.IOException; imp ... -
hadoop 输出格式
2012-04-05 17:18 723http://blog.csdn.net/dajuezhao/ ... -
hadoop mapreduce 原理
2012-03-31 16:14 677http://www.cnblogs.com/forfutur ... -
hadoop搭建问题
2012-03-30 13:23 802file:///E:/hadoop/搭建/hadoop集群搭建 ... -
hadoop输出文件格式
2012-03-26 10:09 640http://apps.hi.baidu.com/share/ ... -
hadoop 学习
2012-03-26 09:48 636http://hi.baidu.com/shuyan50/bl ... -
hadoop提高性能建议
2012-03-22 22:40 669http://langyu.iteye.com/blog/91 ... -
hadoop例子
2012-03-22 22:09 725http://www.hadoopor.com/thread- ... -
hadoop
2012-04-25 13:16 748精通HADOOP http://blog.csdn.net/ ... -
Hadoop Hive与Hbase整合
2012-03-07 15:02 346http://www.open-open.com/lib/vi ... -
hive hadoop 代码解析
2012-04-25 13:16 772http://www.tbdata.org/archives/ ... -
Hadoop MapReduce操作MySQL
2012-03-05 17:33 887http://www.javabloger.com/artic ... -
hadoop hdfs常用操作类
2012-03-05 10:03 1938import java.io.IOException; ... -
hdfs 操作类自己的
2012-03-02 17:57 543package operateFile; import ... -
hadoo 文件常用操作
2012-03-02 15:53 747http://www.360doc.com/content/1 ... -
hadoop基础知识
2012-03-02 08:00 715http://www.blogjava.net/killme2 ... -
hadoop 自己封装的接口
2012-04-25 13:16 677http://www.360doc.com/content/1 ... -
HadoopFileUtil
2012-03-01 14:42 1833import java.io.File; import jav ... -
hadoop ExtendedFileUtil
2012-03-01 14:34 1042在Hadoop编写生产环境的任务时,定义以下任务,要求是相同的 ... -
hadoop StringUtil
2012-03-01 14:33 845import java.util.*; public cla ...
相关推荐
本文将详细讲解如何使用Java程序生成Mybatis的mapper.xml和mapper.java文件,以便于简化开发过程,提高代码的可维护性和效率。 首先,理解mapper.xml和mapper.java的作用是关键。mapper.xml文件是Mybatis中的SQL...
用mybatis-plus的自动生成器,我们一般只用到entity和mapperXML,其他mapper接口和service类都要自己写。 可以下载之后,根据自己表生成mapperXML,然后用全局替换来修改一些细节。
IDEA的这款插件通过解析Java代码中的注解和类结构,自动关联Mapper接口与Mapper XML文件,使得开发者只需在Mapper Java文件中右键点击方法,就能快速打开相应的Mapper XML。这种方式极大地简化了开发者的操作步骤,...
在Hadoop项目开发中,Mapper类和Reducer类是核心组件,负责处理分布式计算的数据流。为了正确地编译和运行这些类,我们需要依赖一系列的jar包。这些jar包提供了Hadoop框架所需的基本功能,以及与网络通信、计算、...
MyBatis SQL mapper framework for Java
"Java根据数据库表名生产mapper和模型类"是开发过程中的一种自动化策略,旨在提高开发效率,减少手动编写代码的工作量。这个过程通常涉及到以下几个关键技术点: 1. **元数据获取**:首先,我们需要连接到数据库,...
在Java开发过程中,Model和Mapper是两个非常关键的组件,特别是在使用ORM(对象关系映射)框架如MyBatis时。Model类代表数据库中的表结构,而Mapper接口则用于执行SQL查询并映射结果到Java对象。手动编写这些文件...
在MyBatis中,Mapper是实现数据库操作的关键组件,它允许开发者将SQL语句与Java代码分离,使得代码更加清晰、易于维护。Mapper映射配置文件是MyBatis的核心组成部分,用于定义SQL查询和结果映射。 首先,我们来看...
如果需要扩展某些特定的SQL操作,可以在`mapper.java`模板中添加相应的方法声明。 3. **自定义Mapper XML文件模板**:Mapper XML文件模板则用于生成对应的XML配置文件,定义SQL语句。根据项目需求,可能需要自定义...
1. Mapper文件:在Java Web开发中,Mapper通常是指MyBatis框架中的Mapper接口,用于定义SQL操作。代码生成器可以根据数据库表结构自动生成对应的Mapper接口和XML配置文件,包含增删查改(INSERT、DELETE、SELECT、...
而Mapper XML文件则包含了具体的SQL语句和结果映射配置,使得SQL与Java代码解耦,提高了代码的可读性和可维护性。通过工具生成的Mapper,开发者可以根据实际需求,在此基础上进行扩展,比如添加更复杂的联表查询或...
在Java的Web开发中,MyBatis作为一款强大的持久层框架,被广泛应用。它简化了数据库操作,将SQL语句与Java代码分离,使得代码更加整洁。本话题将深入探讨如何通过继承Mapper接口来实现无需大量编写mapper.xml文件,...
- 极大地提高了开发效率,减少了大量的模板代码编写。 - 支持动态SQL,可以根据实际需求灵活配置。 - 对于简单的CRUD操作,几乎无需编写额外的代码。 #### 四、通用Mapper视频学习重点 1. **基础概念理解**: ...
你可以使用`org.springframework.hadoop.mapreduce.MapReduceConfigurer`来配置Mapper和Reducer类,以及相关参数。 6. **Job执行和监控**:Spring提供了`org.springframework.hadoop.mapreduce....
1.codeFactory: Java代码生成,依赖rapid-generator.4.0.6.jar, 支持自定义模板生成代码, 弱业务下完全解放体力劳动. 2.ssm模板实现:pojo,dao,daoimpl,service,serviceimpl,controller,各mapper.xml 代码自动生成, 3....
Java8的ModelMapper模块 这是支持Java 8功能的模块。Java 8日期/时间注册模块modelMapper . registerModule( new Jsr310Module ());配置我们还支持配置。 // using String patternsJsr310ModuleConfig config = Jsr...
MyBatis SQL 映射器框架使关系数据库与面向对象的应用程序更容易使用。MyBatis 使用 XML 描述符或注解将对象与存储过程或 SQL 语句耦合在一起。简单性是 MyBatis 数据映射器相对于对象关系映射工具的最大优势。
AlbumsPro5Mapper.java
java-object-mapper-benchmark, Java对象到对象映射框架的JMH基准 Object-to-object映射框架微模块多层应用程序通常需要在不同对象模型之间进行映射( 比如 。 ipqos和实体。写这样的锅炉板映射代码是一个令人烦恼和...