file1:
a 1
b 2
c 3
file2:
1 !
2 @
3 #
file1和file2进行关联,想要的结果:
a !
b @
3 #
1、标记不同输入文件
2、将file1的key、value颠倒 ;file1和file2的key相同,file1的value做key,file2的value做value ,输出。
package smiple;
import java.io.IOException;
import java.util.StringTokenizer;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.InputSplit;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.Mapper;
import org.apache.hadoop.mapreduce.Reducer;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.input.FileSplit;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;
import org.apache.hadoop.util.GenericOptionsParser;
public class FileJoin {
public static class MyMap extends Mapper<LongWritable , Text, Text, Text> {
public void map(LongWritable key, Text value, Context context)throws IOException, InterruptedException {
// String line = value.toString();
String line=new String(value.getBytes(),0,value.getLength(),"GBK");
StringTokenizer tokenizer = new StringTokenizer(line);
String keystr = tokenizer.nextToken();
String valuestr = tokenizer.nextToken();
//获取文件名
InputSplit inputSplit = context.getInputSplit();
String fileName = ((FileSplit) inputSplit).getPath().getName();
if("file1".equals(fileName)){//加标记
context.write(new Text(valuestr),new Text("file1_"+keystr));
}else if("file2".equals(fileName)){
context.write(new Text(keystr), new Text("file2_"+valuestr));
}
}
}
public static class MyReduce extends Reducer<Text, Text, Text, Text> {
public void reduce(Text key, Iterable<Text> values,Context context) throws IOException, InterruptedException {
Text resultKey = new Text("key0");
Text resultValue = new Text("value0");
for (Text val : values) {
if("file1_".equals(val.toString().substring(0, 6))){
resultKey = new Text(val.toString().substring(6));
}else if("file2_".equals(val.toString().substring(0, 6))){
resultValue = new Text(val.toString().substring(6));
}
}
System.out.println(resultKey.toString()+" " + resultValue.toString());
context.write(resultKey, resultValue);
}
}
public static void main(String[] args) throws Exception {
Configuration conf = new Configuration();
String[] ioArgs = new String[] { "hdfs://ip:port/mr/join/in","hdfs://ip:port/mr/join/out" };
String[] otherArgs = new GenericOptionsParser(conf, ioArgs).getRemainingArgs();
if (otherArgs.length != 2) {
System.err.println("Usage: Data Sort <in> <out>");
System.exit(2);
}
Job job = new Job(conf, "file join ");
job.setJarByClass(Sort.class);
// 设置Map和Reduce处理类
job.setMapperClass(MyMap.class);
job.setReducerClass(MyReduce.class);
// 设置输出类型
job.setOutputKeyClass(Text.class);
job.setOutputValueClass(Text.class);
// 设置输入和输出目录
FileInputFormat.addInputPath(job, new Path(otherArgs[0]));
FileOutputFormat.setOutputPath(job, new Path(otherArgs[1]));
System.exit(job.waitForCompletion(true) ? 0 : 1);
}
}
Ubuntu 12.04单机版环境中搭建hadoop详细教程,在Ubuntu下创建hadoop用户组和用,创建hadoop用户。
在mac os上安装hadoop的文章不多,本文安装环境的操作系统是 MAC OS X 10.7 Lion,共分7步,注意第三个配置在OS X上最好进行配置,否则会报错“Unable to load realm info from SCDynamicStore”。
Nutch采用一个MR对爬取下来的文档进行清洗和封装成一个action列表。Nutch会将封装好的数据采用基于http的POST的方法发送一个请求数据包给solr的服务器,solr.commit();这个方法在前面一篇文章中解释有些偏差,solr的整个事务都是在solr服务器端的,这跟以前的的事务有所
、默认项目名称为MapReduceTools,然后在项目MapReduceTools中新建lib目录,先将hadoop下的hadoop-core-1.0.4.jar重命名为hadoop.core.jar,并把hadoop.core.jar、及其lib目录下的commons-cli-1.2.jar、commons-lang-2.4.jar、commons-configuration-1.6.jar、jackson-m
SAP特别设立了一个“大数据”合作伙伴理事会。该理事会致力于进行合作创新,研发基于SAP实时数据平台和Hadoop的新产品解决方案,探索新应用和架构
【聚焦搜索,数智采购】2021第一届百度爱采购数智大会即将于5月28日在上海盛大开启!
本次大会上,紫晶存储董事、总经理钟国裕作为公司代表,与中国—东盟信息港签署合作协议
XEUS统一存储已成功承载宣武医院PACS系统近5年的历史数据迁移,为支持各业务科室蓬勃扩张的数据增量和访问、调用乃至分析需求奠定了坚实基础。
大兆科技全方面展示大兆科技在医疗信息化建设中数据存储系统方面取得的成就。
双方相信,通过本次合作,能够使双方进一步提升技术实力、提升产品品质及服务质量,为客户创造更大价值。