- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试编写一个mapreduce程序,其中map函数将项目添加到HashMap,然后reducer访问这些项目并将其写入输出。
public class MyClass {
static HashMap<String, Integer> temp = new HashMap<String, Integer>();
public static class Map1 extends Mapper<LongWritable, Text, Text, IntWritable> {
public void map(LongWritable key, Text value, Context context) {
temp.put("1", 1);
}
}
public static class Reduce1 extends Reducer<Text, IntWritable, Text, Text> {
@Override
public void reduce(Text key, Iterable<IntWritable> values, Context context) {
Iterator it = temp.entrySet().iterator();
while (it.hasNext()) {
Map.Entry<String, Integer> pair = (Map.Entry<String, Integer>)it.next();
String key = pair.getKey();
String val = Integer.toString(pair.getValue());
context.write(new Text(key), new Text(val));
}
}
}
这编译得很好,但是 reducer 的输出是空的。我不太擅长 Java,所以我不太确定这里出了什么问题。
最佳答案
您误解了 MapReduce 是一种在许多进程和潜在机器之间运行的分布式算法。
在此过程中创建的每个新 MyClass
实例都将为空,并且不会作为应用程序生命周期的一部分进行共享
另外,你的映射器什么也没做。向reducer发送数据的方式是使用context.write
。
有关字数统计代码,请参阅 Hadoop 官方文档。
关于java - 在mapreduce中访问mapper/reducer类之外的静态HashMap,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59996545/
我正在处理一个处理大量数据的项目,所以我最近发现了 MapReduce,在我进一步深入研究之前,我想确保我的期望是正确的。 与数据的交互将通过 Web 界面进行,因此响应时间在这里至关重要,我认为 1
我正在阅读有关 Hadoop 以及它的容错性的文章。我阅读了 HDFS 并阅读了如何处理主节点和从节点的故障。但是,我找不到任何提及 mapreduce 如何执行容错的文档。特别是,当包含 Job T
我正在尝试在我的 Ubuntu 桌面上使用最新的 Hadoop 版本 2.6.0、Java SDK 1.70 来模拟 Hadoop 环境。我用必要的环境参数配置了 hadoop,它的所有进程都已启动并
就目前情况而言,这个问题不太适合我们的问答形式。我们希望答案得到事实、引用资料或专业知识的支持,但这个问题可能会引发辩论、争论、民意调查或扩展讨论。如果您觉得这个问题可以改进并可能重新开放,visit
我只是想针对我们正在做的一些数据分析工作来评估 HBase。 HBase 将包含我们的事件数据。键为 eventId + 时间。我们想要对日期范围内的几种事件类型 (4-5) 进行分析。事件类型总数约
是否有一种快速算法可以在 MapReduce 框架上运行以从巨大的整数集中查找中位数? 最佳答案 我会这样做。这是顺序快速选择的一种并行版本。 (某些映射/归约工具可能不会让您轻松完成任务...) 从
我正在尝试对大型分布式数据集执行一些数值计算。该算法非常适合 MapReduce 模型,具有以下附加属性:与输入数据相比,映射步骤的输出尺寸较小。数据可以被视为只读,并且静态分布在节点上(故障转移时的
假设我在 RavenDb 中有给定的文档结构 public class Car { public string Manufacturer {get;set;} public int B
我刚刚开始使用 mongo 和 map/reduce,在使用 pymongo 时我遇到了以下错误,而在直接使用 mongo 命令行时我没有得到(我意识到有一个类似的问题这个,但我的似乎更基本)。 我直
*基本上我正在尝试按过去一小时内的得分对对象进行排序。 我正在尝试为我的数据库中的对象生成每小时投票总和。投票嵌入到每个对象中。对象架构如下所示: { _id: ObjectId sc
我们怎样才能使我们的 MapReduce 查询更快? 我们使用五节点 Riak 数据库集群构建了一个应用程序。 我们的数据模型由三个部分组成:比赛、联赛和球队。 比赛包含联赛和球队的链接: 型号 va
关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。 我们不允许提问寻求书籍、工具、软件库等的推荐。您可以编辑问题,以便用事实和引用来回答。 关闭 6 年前。
有没有什么方法可以在运行时获取应用程序 ID - 例如 - 带有 yarn 的 wordcount 示例命令? 我希望使用 yarn 从另一个进程启 Action 业命令,并通过 YARN REST
如何在Hadoop Map-reduce程序中使用机器学习算法?我想使用分类算法、决策树、聚类算法。除了 Mahout 之外,请提出一些想法。 最佳答案 您可以编写自己的MapReduce程序,并在m
虽然 MapReduce 可能不是实现图像处理中使用的算法的最佳方式,但出于好奇,如果我作为初学者尝试使用它们,这将是最简单的实现方式。 最佳答案 Hadoop 非常适合处理大量 IO。因此,例如,您
我只是想验证我对这些参数及其关系的理解,如果我错了请通知我。 mapreduce.reduce.shuffle.input.buffer.percent 告诉分配给 reducer 的整个洗牌阶段的内
HBase 需要 mapreduce/yarn,还是只需要 hdfs? 对于 HBase 的基本用法,例如创建表、插入数据、扫描/获取数据,我看不出有任何理由使用 mapreduce/yarn。 请帮
我问了一些关于提高 Hive 查询性能的问题。一些答案与映射器和化简器的数量有关。我尝试了多个映射器和化简器,但在执行过程中没有发现任何差异。不知道为什么,可能是我没有以正确的方式去做,或者我错过了别
我是 mapreduce 和 hadoop 的新手。我阅读了 mapreduce 的示例和设计模式... 好的,我们可以进入正题了。我们正在开发一种软件,可以监控系统并定期捕获它们的 CPU 使用
我正在使用 Microsoft MapReduce SDK 启动仅 Mapper 作业。 调用 hadoop.MapReduceJob.ExecuteJob 立即抛出“响应状态代码不表示成功:404(
我是一名优秀的程序员,十分优秀!