- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我有 mapreduce 工作:我的代码 map 类:
public static class MapClass extends Mapper<Text, Text, Text, LongWritable> {
@Override
public void map(Text key, Text value, Context context)
throws IOException, InterruptedException {
}
}
我想使用 ChainMapper :
1. Job job = new Job(conf, "Job with chained tasks");
2. job.setJarByClass(MapReduce.class);
3. job.setInputFormatClass(TextInputFormat.class);
4. job.setOutputFormatClass(TextOutputFormat.class);
5. FileInputFormat.setInputPaths(job, new Path(InputFile));
6. FileOutputFormat.setOutputPath(job, new Path(OutputFile));
7. JobConf map1 = new JobConf(false);
8. ChainMapper.addMapper(
job,
MapClass.class,
Text.class,
Text.class,
Text.class,
Text.class,
true,
map1
);
但它的报告在第 8 行有错误:
Multiple markers at this line - Occurrence of 'addMapper' - The method addMapper(JobConf, Class>, Class, Class, Class, Class, boolean, JobConf) in the type ChainMapper is not applicable for the arguments (Job, Class, Class, Class, Class, Class, boolean, Configuration) - Debug Current Instruction Pointer - The method addMapper(JobConf, Class>, Class, Class, Class, Class, boolean, JobConf) in the type ChainMapper is not applicable for the arguments (JobConf, Class, Class, Class, Class, Class, boolean, JobConf)
最佳答案
经过大量的“功夫”,我能够使用ChainMapper/ChainReducer
。感谢 user864846 的最后评论。
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package myPKG;
/*
* Ajitsen: Sample program for ChainMapper/ChainReducer. This program is modified version of WordCount example available in Hadoop-0.18.0. Added ChainMapper/ChainReducer and made to works in Hadoop 1.0.2.
*/
import java.io.IOException;
import java.util.Iterator;
import java.util.StringTokenizer;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.conf.Configured;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapred.*;
import org.apache.hadoop.mapred.lib.ChainMapper;
import org.apache.hadoop.mapred.lib.ChainReducer;
import org.apache.hadoop.util.Tool;
import org.apache.hadoop.util.ToolRunner;
public class ChainWordCount extends Configured implements Tool {
public static class Tokenizer extends MapReduceBase
implements Mapper<LongWritable, Text, Text, IntWritable> {
private final static IntWritable one = new IntWritable(1);
private Text word = new Text();
public void map(LongWritable key, Text value,
OutputCollector<Text, IntWritable> output,
Reporter reporter) throws IOException {
String line = value.toString();
System.out.println("Line:"+line);
StringTokenizer itr = new StringTokenizer(line);
while (itr.hasMoreTokens()) {
word.set(itr.nextToken());
output.collect(word, one);
}
}
}
public static class UpperCaser extends MapReduceBase
implements Mapper<Text, IntWritable, Text, IntWritable> {
public void map(Text key, IntWritable value,
OutputCollector<Text, IntWritable> output,
Reporter reporter) throws IOException {
String word = key.toString().toUpperCase();
System.out.println("Upper Case:"+word);
output.collect(new Text(word), value);
}
}
public static class Reduce extends MapReduceBase
implements Reducer<Text, IntWritable, Text, IntWritable> {
public void reduce(Text key, Iterator<IntWritable> values,
OutputCollector<Text, IntWritable> output,
Reporter reporter) throws IOException {
int sum = 0;
while (values.hasNext()) {
sum += values.next().get();
}
System.out.println("Word:"+key.toString()+"\tCount:"+sum);
output.collect(key, new IntWritable(sum));
}
}
static int printUsage() {
System.out.println("wordcount <input> <output>");
ToolRunner.printGenericCommandUsage(System.out);
return -1;
}
public int run(String[] args) throws Exception {
JobConf conf = new JobConf(getConf(), ChainWordCount.class);
conf.setJobName("wordcount");
if (args.length != 2) {
System.out.println("ERROR: Wrong number of parameters: " +
args.length + " instead of 2.");
return printUsage();
}
FileInputFormat.setInputPaths(conf, args[0]);
FileOutputFormat.setOutputPath(conf, new Path(args[1]));
conf.setInputFormat(TextInputFormat.class);
conf.setOutputFormat(TextOutputFormat.class);
JobConf mapAConf = new JobConf(false);
ChainMapper.addMapper(conf, Tokenizer.class, LongWritable.class, Text.class, Text.class, IntWritable.class, true, mapAConf);
JobConf mapBConf = new JobConf(false);
ChainMapper.addMapper(conf, UpperCaser.class, Text.class, IntWritable.class, Text.class, IntWritable.class, true, mapBConf);
JobConf reduceConf = new JobConf(false);
ChainReducer.setReducer(conf, Reduce.class, Text.class, IntWritable.class, Text.class, IntWritable.class, true, reduceConf);
JobClient.runJob(conf);
return 0;
}
public static void main(String[] args) throws Exception {
int res = ToolRunner.run(new Configuration(), new ChainWordCount(), args);
System.exit(res);
}
}
编辑 在最新版本中(至少从 hadoop 2.6 开始),不需要 addMapper 中的 true
标志。 (实际上签名有变化抑制它`)。
那就是
JobConf mapAConf = new JobConf(false);
ChainMapper.addMapper(conf, Tokenizer.class, LongWritable.class, Text.class,
Text.class, IntWritable.class, mapAConf);
关于java - Hadoop mapreduce : Driver for chaining mappers within a MapReduce job,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6840922/
我正在尝试获取此亚马逊页面中列出的每台笔记本电脑的图像 URL ( https://www.amazon.com/s?rh=n%3A565108%2Cp_72%3A4-&pf_rd_i=565108&
我正在设置 Atlassian Confluence,在选择数据库时,我在选择“使用外部 Mysql 数据库”时卡住了我看过一些教程,但对我来说,它并没有按照应有的方式工作。我使用 ubuntu 12
我是 Neo4J 的新手,正在尝试通过 java 连接到 Neo4J 服务器。 我的一个独立项目的pom入口如下: org.neo4j neo4j-o
所有这些有什么区别和用途? spark.local.ip spark.driver.host spark.driver.bind地址 spark.driver.hostname 如何将机器修复为 Sp
我在旧的 Inspiron 6400 计算机(GeForce 7300 笔记本电脑版)上安装了 Lubuntu 19.04,通过网络草稿编辑器教我儿子 Scratch。每次我通过 Firefox 打开
我使用 qt 开发了一个 c++ 库。在本文中,我使用 QSqlDatabase 从 SQLite 数据库中查询信息。注意:我的库在 qt 桌面应用程序中运行良好(我在 Linux 上开发)。 现在我
存在类似的问题,但没有帮助。 在 Apache 2.4 上安装 php5-fpm 通过 SSL 连接到远程 MySql 数据库。 可以通过命令行连接MySQL mysql -u myname -p'p
使用以下配置 (doctrine.yaml) 在 Symfony 4 中使用 Doctrine DBAL: dbal: # configure these for your database
使用以下配置 (doctrine.yaml) 在 Symfony 4 中使用 Doctrine DBAL: dbal: # configure these for your database
我有一个用 Java 编写的 Selenium Web 驱动程序测试,目标是 Liferay 站点。 // Login driver.get(baseUrl + "/"); driver.findEl
在driver.findElements()中,我们获得了另一个用于查找size()的函数,该函数在driver.findElement()中不可用。 这是唯一的区别吗? 最佳答案 driver.fi
这个问题已经有答案了: java.lang.IllegalStateException: The driver executable does not exist: while trying to e
简短描述:我有一个通过 SignTool 验证的签名驱动程序,但 Windows 拒绝加载它并出现错误:CodeIntegrity 3004 - 在系统上找不到文件哈希。我该如何解决这个问题? 详细说
我正在设置一些 Geb 测试,但出现“geb.driver.DriverCreationException:无法从回调创建驱动程序”错误。 Geb 将尝试启动测试浏览器窗口,但一旦启动,我的所有测试都
我想通过应用对象存储库概念在 Chrome 驱动程序中打开 url。下面给出的是我的 selenium 程序,其中包含两个文件,一个是 testng 文件,另一个是 config.property 文
我在 Ubuntu Linux、Spring Tools 2.7.1、Spring Roo 1.1.5 上运行 Eclipse Indigo。我正在阅读 Getting Started with Ro
打开 Url 的首选方法是什么(它们之间是否存在任何差异): driver.Url = "http://example.com"; 或 driver.Navigate().GoToUrl("http:
我使用 python 脚本传递给 cassandra 批处理查询,如下所示: query = 'BEGIN BATCH ' + 'insert into ... ; insert into ... ;
我在 Protractor 中执行脚本时出现以下错误。 System info: host: '8888', ip: '88888', os.name: 'Mac OS X', os.arch: 'x
我收到错误 KeyError:'driver'。 我想使用scrapy-selenium 创建一个网络爬虫。我的代码如下所示: class TestSpider(Spider): name="test
我是一名优秀的程序员,十分优秀!