- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我编写了一个小型 mapreduce 作业来查找数据集中第二高的薪水。我相信第二高的薪水逻辑是正确的。但是我得到的多个输出是不正确的,应该只有一个带有名称的输出,例如 John,9000。而且输出也不正确,我在这里给出数据集和代码
hh,0,Jeet,3000
hk,1,Mayukh,4000
nn,2,Antara,3500
mm,3,Shubu,6000
ii,4,Parsi,8000
输出应该是 Shubu,6000 ,但是我得到的是下面的输出
Antara -2147483648
Mayukh -2147483648
Parsi 3500
Shubu 4000
我使用的代码是
public class SecondHigestMapper extends Mapper<LongWritable,Text,Text,Text>{
private Text salary = new Text();
private Text name = new Text();
public void map(LongWritable key,Text value,Context context) throws IOException, InterruptedException{
if(key.get()!=0){
String split[]= value.toString().split(",");
salary.set(split[2]+";"+split[3]);
name.set("ignore");
context.write(name,salary);
}
}
}
public class SecondHigestReducer extends Reducer<Text,Text,Text,IntWritable>{
public void reduce(Text key,Iterable<Text> values,Context context) throws IOException, InterruptedException{
int highest = 0;
int second_highest = 0;
int salary;
for(Text val:values){
String[] fn = val.toString().split("\\;");
salary = Integer.parseInt(fn[3]);
if(highest < salary){
second_highest = highest;
highest =salary;
} else if(second_highest < salary){
second_highest = salary;
}
}
String seconHigest = String.valueOf(second_highest);
context.write(new Text(key),new Text(seconHigest));
}
}
public class SecondHigestDriver {
public static void main(String[] args) throws IOException, ClassNotFoundException, InterruptedException {
Configuration conf = new Configuration();
Job job = new Job(conf,"Second Higest Sal");
job.setJarByClass(SecondHigestDriver.class);
job.setMapperClass(SecondHigestMapper.class);
job.setCombinerClass(SecondHigestReducer.class);
job.setReducerClass(SecondHigestReducer.class);
job.setOutputKeyClass(Text.class);
job.setMapOutputValueClass(Text.class);
FileInputFormat.addInputPath(job, new Path(args[0]));
FileOutputFormat.setOutputPath(job, new Path(args[1]));
System.exit(job.waitForCompletion(true) ? 0 : 1);
}
}
我正在低于异常
Error: java.io.IOException: Type mismatch in value from map: expected org.apache.hadoop.io.IntWritable, received org.apache.hadoop.io.Text
at org.apache.hadoop.mapred.MapTask$MapOutputBuffer.collect(MapTask.java:1074)
at org.apache.hadoop.mapred.MapTask$NewOutputCollector.write(MapTask.java:712)
at org.apache.hadoop.mapreduce.task.TaskInputOutputContextImpl.write(TaskInputOutputContextImpl.java:89)
at org.apache.hadoop.mapreduce.lib.map.WrappedMapper$Context.write(WrappedMapper.java:112)
at com.jeet.secondhigest.SecondHigestMapper.map(SecondHigestMapper.java:20)
at com.jeet.secondhigest.SecondHigestMapper.map(SecondHigestMapper.java:1)
at org.apache.hadoop.mapreduce.Mapper.run(Mapper.java:145)
at org.apache.hadoop.mapred.MapTask.runNewMapper(MapTask.java:784)
at org.apache.hadoop.mapred.MapTask.run(MapTask.java:341)
at org.apache.hadoop.mapred.YarnChild$2.run(YarnChild.java:168)
at java.security.AccessController.doPrivileged(Native Method)
at javax.security.auth.Subject.doAs(Subject.java:422)
at org.apache.hadoop.security.UserGroupInformation.doAs(UserGroupInformation.java:1642)
at org.apache.hadoop.mapred.YarnChild.main(YarnChild.java:163)
请帮我解决这个问题
最佳答案
使用一个键将所有薪水强制放入一个 reducer 中
name.set("ignore"); // Could use a NullWritable
salary.set(split[2]+";"+split[3])); // change to TextWritable
context.write(name,salary); // need to change the signature of the mapper class
然后在 reducer 中,改变接受文本值的方法,然后将它们分开,转换薪水,然后比较它们
关于java - 使用 mapreduce 的第二大薪水 - 输出不符合预期,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51006960/
我正在处理一个处理大量数据的项目,所以我最近发现了 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(
我是一名优秀的程序员,十分优秀!