• linkedu视频
  • 平面设计
  • 电脑入门
  • 操作系统
  • 办公应用
  • 电脑硬件
  • 动画设计
  • 3D设计
  • 网页设计
  • CAD设计
  • 影音处理
  • 数据库
  • 程序设计
  • 认证考试
  • 信息管理
  • 信息安全
菜单
linkedu.com
导航菜单
  • 网页制作
  • 数据库
  • 程序设计
  • 操作系统
  • CMS教程
  • 游戏攻略
  • 脚本语言
  • 平面设计
  • 软件教程
  • 网络安全
  • 电脑知识
  • 服务器
  • 视频教程
  • windows
  • 服务器硬件
  • 服务器运维
  • 云计算
  • 虚拟化
  • IIS教程
  • Linux
  • Apache
  • Ftp
  • DNS
  • Nginx
您的位置:首页 > 服务器 >云计算 > MapReduce实现倒排索引,mapreduce实现索引

MapReduce实现倒排索引,mapreduce实现索引

作者:网友 字体:[增加 减小] 来源:互联网

本文主要包含mapreduce倒排索引,mapreduce实现圆周率,mapreduce实现排序,mapreduce,mapreduce是什么等服务器相关知识,网友希望可以进行参考

MapReduce实现倒排索引,mapreduce实现索引


使用到Combiner编程(可插拔式)

在map端对输出先做合并,最基本是实现本地key合并,具有本地reduce功能

如果不用combiner,所有结果都是reduce完成,效率会底下

Combiner的的输入输出类型应该完全一致(实现如累加,最大值等功能)

job.setCombinerClass();

倒排索引基本实现

package cn.MapReduce.px;

import java.io.IOException;

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

public class InverIndex {
	/*
	 * dao pai suoyin
	 */
	public static class InverIndexMap extends
			Mapper<LongWritable, Text, Text, Text> {

		private Text k2 = new Text();
		private Text v2 = new Text();

		protected void map(LongWritable key, Text value, Context context)
				throws IOException, InterruptedException {
			String line = value.toString();
			String words[] = line.split(" ");
			// get fileObject
			FileSplit inputSplit = (FileSplit) context.getInputSplit();
			String path = inputSplit.getPath().toString();
			for (String word : words) {
				String WordAndPath = word + "->" + path;
				k2.set(WordAndPath);
				v2.set("1");
				context.write(k2, v2);
			}

		}
	}

	public static class InverIndexCombiner extends
			Reducer<Text, Text, Text, Text> {

		private Text k4 = new Text();
		private Text v4 = new Text();

		protected void reduce(Text k3, Iterable<Text> v3s, Context context)
				throws IOException, InterruptedException {
			String word = k3.toString().split("->")[0];
			String path = k3.toString().split("->")[1];
			Integer count = 0;
			for (Text t : v3s) {
				count += Integer.parseInt(t.toString());
			}
			String PathAndCount = path + "->" + count;
			k4.set(word);
			v4.set(PathAndCount);
			context.write(k4, v4);
		}

	}

	public static class InverIndexReduce extends
			Reducer<Text, Text, Text, Text> {

		private Text v6 = new Text();

		protected void reduce(Text k5, Iterable<Text> v5s, Context context)
				throws IOException, InterruptedException {
			String result = "";
			for (Text t : v5s) {
				result += t.toString() + "\t";
			}
			v6.set(result);
			context.write(k5, v6);
		}

	}

	public static void main(String[] args) throws Exception {
		Job job = Job.getInstance(new Configuration());
		job.setJarByClass(InverIndex.class);
		job.setMapperClass(InverIndexMap.class);
		job.setMapOutputKeyClass(Text.class);
		job.setMapOutputValueClass(Text.class);
		FileInputFormat.setInputPaths(job, new Path(args[0]));

		job.setCombinerClass(InverIndexCombiner.class);
		job.setReducerClass(InverIndexReduce.class);
		job.setOutputKeyClass(Text.class);
		job.setOutputValueClass(Text.class);
		FileOutputFormat.setOutputPath(job, new Path(args[1]));

		job.waitForCompletion(true);
	}

}


 

 

分享到:QQ空间新浪微博腾讯微博微信百度贴吧QQ好友复制网址打印

您可能想查找下面的文章:

  • MapReduce编程之倒排索引,mapreduce编程索引
  • MapReduce实现倒排索引,mapreduce实现索引

相关文章

  • 微软云和阿里云的区别,微软云和阿里
  • Elasticsearch之Nested Object Mapping,elasticsearch
  • Apache MRQL——Apache又一开源孵化利器,mrqlapache
  • 【解决】hive动态增加partitions不能超过100的问题,hivepartitions
  • 【Spark1.3官方翻译】Spark快速入门,spark1.3spark
  • HIVE的数据存储,HIVE数据存储
  • Hadoop之——HBASE结合MapReduce批量导入数据,hadoopmapreduce
  • kafka 效率优化,kafka优化
  • Spark源码分析之worker节点启动driver和executor
  • 云计算容器服务该何去何从,容器该何去何从

文章分类

  • windows
  • 服务器硬件
  • 服务器运维
  • 云计算
  • 虚拟化
  • IIS教程
  • Linux
  • Apache
  • Ftp
  • DNS
  • Nginx

最近更新的内容

    • Spark下的PageRank实现,SparkPageRank实现
    • word2vec.c源码分析,word2vec.c源码
    • 闰秒导致hadoop集群崩溃,闰秒hadoop集群
    • hadoop-2.6.0运行woudcount报错,hadoop运行wordcount
    • JOIN操作,数据库join操作
    • 浅谈大数据,浅谈数据
    • Andrew Ng Machine Learning,andrewlearning
    • Docker学习笔记(一):Docker的三个基本概念,docker学习笔记
    • 架构设计(ASP.NET MVC+Knockout+Web API+SignalR),knockoutsignalr
    • &lt;转&gt;云主机配置OpenStack使用spice的方法,openstackspice

关于我们 - 联系我们 - 免责声明 - 网站地图

©2020-2025 All Rights Reserved. linkedu.com 版权所有