- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我有这个 hadoop 程序:
import java.io.IOException;
import org.apache.hadoop.conf.Configuration;
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.mapreduce.Mapper;
import org.apache.hadoop.mapreduce.Reducer;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.input.TextInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;
import org.apache.hadoop.mapreduce.lib.output.TextOutputFormat;
import org.apache.hadoop.util.GenericOptionsParser;
import org.apache.hadoop.mapreduce.Job;
public class Question1_1 {
public static class WordCountMapper extends Mapper<LongWritable, Text, Text, IntWritable> {
@Override
protected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {
for (String word : value.toString().split("\\s+")) {
context.write(new Text(word), new IntWritable(1));
}
}
}
public static class WordCountReducer extends Reducer<Text, IntWritable, Text, IntWritable> {
@Override
protected void reduce(Text key, Iterable<IntWritable> values, Context context)
throws IOException, InterruptedException {
int sum = 0;
for (IntWritable value : values) {
sum += value.get();
}
context.write(key, new IntWritable(sum));
}
}
public static void main(String[] args) throws Exception {
Configuration conf = new Configuration();
String[] otherArgs = new GenericOptionsParser(conf, args).getRemainingArgs();
Job job = Job.getInstance(conf, "Question1_1");
job.setJarByClass(Question1_1.class);
job.setMapperClass(WordCountMapper.class);
job.setReducerClass(WordCountReducer.class);
// Types of Key/Value
job.setMapOutputKeyClass(Text.class);
job.setMapOutputValueClass(IntWritable.class);
job.setOutputKeyClass(Text.class);
job.setOutputValueClass(LongWritable.class);
job.setInputFormatClass(TextInputFormat.class);
job.setOutputFormatClass(TextOutputFormat.class);
// Input & Output Files
FileInputFormat.addInputPath(job, new Path(otherArgs[0]));
FileOutputFormat.setOutputPath(job, new Path(otherArgs[1]));
System.exit(job.waitForCompletion(true) ? 0 : 1);
}
}
我针对一个 txt 文件运行这个程序。我在日志中得到了这个:
15:09:11 WARN util.NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicable
15:09:12 INFO Configuration.deprecation: session.id is deprecated. Instead, use dfs.metrics.session-id
15:09:12 INFO jvm.JvmMetrics: Initializing JVM Metrics with processName=JobTracker, sessionId=
15:09:12 WARN mapreduce.JobSubmitter: No job jar file set. User classes may not be found. See Job or Job#setJar(String).
15:09:12 INFO input.FileInputFormat: Total input paths to process : 1
15:09:12 INFO mapreduce.JobSubmitter: number of splits:1
15:09:12 INFO Configuration.deprecation: mapred.job.name is deprecated. Instead, use mapreduce.job.name
15:09:12 INFO Configuration.deprecation: mapreduce.map.class is deprecated. Instead, use mapreduce.job.map.class
15:09:12 INFO Configuration.deprecation: mapred.input.dir is deprecated. Instead, use mapreduce.input.fileinputformat.inputdir
15:09:12 INFO Configuration.deprecation: mapreduce.reduce.class is deprecated. Instead, use mapreduce.job.reduce.class
15:09:12 INFO Configuration.deprecation: mapreduce.inputformat.class is deprecated. Instead, use mapreduce.job.inputformat.class
15:09:12 INFO Configuration.deprecation: mapreduce.outputformat.class is deprecated. Instead, use mapreduce.job.outputformat.class
15:09:12 INFO Configuration.deprecation: mapred.output.value.class is deprecated. Instead, use mapreduce.job.output.value.class
15:09:12 INFO Configuration.deprecation: mapred.output.dir is deprecated. Instead, use mapreduce.output.fileoutputformat.outputdir
15:09:12 INFO Configuration.deprecation: mapred.working.dir is deprecated. Instead, use mapreduce.job.working.dir
15:09:12 INFO Configuration.deprecation: mapreduce.combine.class is deprecated. Instead, use mapreduce.job.combine.class
15:09:12 INFO Configuration.deprecation: mapred.mapoutput.value.class is deprecated. Instead, use mapreduce.map.output.value.class
15:09:12 INFO Configuration.deprecation: mapred.map.tasks is deprecated. Instead, use mapreduce.job.maps
15:09:12 INFO Configuration.deprecation: mapred.mapoutput.key.class is deprecated. Instead, use mapreduce.map.output.key.class
15:09:12 INFO Configuration.deprecation: user.name is deprecated. Instead, use mapreduce.job.user.name
15:09:12 INFO Configuration.deprecation: mapred.reduce.tasks is deprecated. Instead, use mapreduce.job.reduces
15:09:12 INFO Configuration.deprecation: mapred.output.key.class is deprecated. Instead, use mapreduce.job.output.key.class
15:09:12 INFO mapreduce.JobSubmitter: Submitting tokens for job: job_local958404083_0001
15:09:12 WARN conf.Configuration: file:/tmp/hadoop-hamza/mapred/staging/hamza958404083/.staging/job_local958404083_0001/job.xml:an attempt to override final parameter: mapreduce.job.end-notification.max.retry.interval; Ignoring.
15:09:12 WARN conf.Configuration: file:/tmp/hadoop-hamza/mapred/staging/hamza958404083/.staging/job_local958404083_0001/job.xml:an attempt to override final parameter: mapreduce.job.end-notification.max.attempts; Ignoring.
15:09:12 WARN conf.Configuration: file:/tmp/hadoop-hamza/mapred/local/localRunner/hamza/job_local958404083_0001/job_local958404083_0001.xml:an attempt to override final parameter: mapreduce.job.end-notification.max.retry.interval; Ignoring.
15:09:12 WARN conf.Configuration: file:/tmp/hadoop-hamza/mapred/local/localRunner/hamza/job_local958404083_0001/job_local958404083_0001.xml:an attempt to override final parameter: mapreduce.job.end-notification.max.attempts; Ignoring.
15:09:12 INFO mapreduce.Job: The url to track the job: http://localhost:8080/
15:09:12 INFO mapreduce.Job: Running job: job_local958404083_0001
15:09:12 INFO mapred.LocalJobRunner: OutputCommitter set in config null
15:09:12 INFO mapred.LocalJobRunner: OutputCommitter is org.apache.hadoop.mapreduce.lib.output.FileOutputCommitter
15:09:12 INFO mapred.LocalJobRunner: Waiting for map tasks
15:09:12 INFO mapred.LocalJobRunner: Starting task: attempt_local958404083_0001_m_000000_0
15:09:12 INFO mapred.Task: Using ResourceCalculatorProcessTree : [ ]
15:09:12 INFO mapred.MapTask: Processing split: file:/home/hamza/workspace/TPIntroHadoop/flickrSample.txt:0+53568
15:09:12 INFO mapred.MapTask: Map output collector class = org.apache.hadoop.mapred.MapTask$MapOutputBuffer
15:09:12 INFO mapred.MapTask: (EQUATOR) 0 kvi 26214396(104857584)
15:09:12 INFO mapred.MapTask: mapreduce.task.io.sort.mb: 100
15:09:12 INFO mapred.MapTask: soft limit at 83886080
15:09:12 INFO mapred.MapTask: bufstart = 0; bufvoid = 104857600
15:09:12 INFO mapred.MapTask: kvstart = 26214396; length = 6553600
15:09:12 INFO mapred.LocalJobRunner:
15:09:12 INFO mapred.MapTask: Starting flush of map output
15:09:12 INFO mapred.MapTask: Spilling map output
15:09:12 INFO mapred.MapTask: bufstart = 0; bufend = 62647; bufvoid = 104857600
15:09:12 INFO mapred.MapTask: kvstart = 26214396(104857584); kvend = 26205172(104820688); length = 9225/6553600
15:09:12 INFO mapred.MapTask: Finished spill 0
15:09:12 INFO mapred.Task: Task:attempt_local958404083_0001_m_000000_0 is done. And is in the process of committing
15:09:12 INFO mapred.LocalJobRunner: map
15:09:12 INFO mapred.Task: Task 'attempt_local958404083_0001_m_000000_0' done.
15:09:12 INFO mapred.LocalJobRunner: Finishing task: attempt_local958404083_0001_m_000000_0
15:09:12 INFO mapred.LocalJobRunner: Map task executor complete.
15:09:12 INFO mapred.Task: Using ResourceCalculatorProcessTree : [ ]
15:09:12 INFO mapred.Merger: Merging 1 sorted segments
15:09:12 INFO mapred.Merger: Down to the last merge-pass, with 1 segments left of total size: 41944 bytes
15:09:12 INFO mapred.LocalJobRunner:
15:09:12 INFO Configuration.deprecation: mapred.skip.on is deprecated. Instead, use mapreduce.job.skiprecords
15:09:12 INFO mapred.Task: Task:attempt_local958404083_0001_r_000000_0 is done. And is in the process of committing
15:09:12 INFO mapred.LocalJobRunner:
15:09:12 INFO mapred.Task: Task attempt_local958404083_0001_r_000000_0 is allowed to commit now
15:09:12 INFO output.FileOutputCommitter: Saved output of task 'attempt_local958404083_0001_r_000000_0' to file:/home/hamza/workspace/TPIntroHadoop/sresult/_temporary/0/task_local958404083_0001_r_000000
15:09:12 INFO mapred.LocalJobRunner: reduce > reduce
15:09:12 INFO mapred.Task: Task 'attempt_local958404083_0001_r_000000_0' done.
15:09:13 INFO mapreduce.Job: Job job_local958404083_0001 running in uber mode : false
15:09:13 INFO mapreduce.Job: map 100% reduce 100%
15:09:13 INFO mapreduce.Job: Job job_local958404083_0001 completed successfully
15:09:13 INFO mapreduce.Job: Counters: 27
File System Counters
FILE: Number of bytes read=149581
FILE: Number of bytes written=496089
FILE: Number of read operations=0
FILE: Number of large read operations=0
FILE: Number of write operations=0
Map-Reduce Framework
Map input records=100
Map output records=2307
Map output bytes=62647
Map output materialized bytes=42089
Input split bytes=122
Combine input records=2307
Combine output records=1218
Reduce input groups=1218
Reduce shuffle bytes=0
Reduce input records=1218
Reduce output records=1218
Spilled Records=2436
Shuffled Maps =0
Failed Shuffles=0
Merged Map outputs=0
GC time elapsed (ms)=0
CPU time spent (ms)=0
Physical memory (bytes) snapshot=0
Virtual memory (bytes) snapshot=0
Total committed heap usage (bytes)=460324864
File Input Format Counters
Bytes Read=53568
File Output Format Counters
Bytes Written=37479
问题:Map输出记录和Reduce输入记录之间有什么关系? Reduce 输入组代表什么?
最佳答案
在映射器中,您使用 context.write(key, value)
在 reducer 中,特定 key
的所有值来自映射器的被组合成 Iterable<?> values
获取要写入的内容 new Path(output)
, 你需要使用 context
再次从 reducer
关于java - 映射输出记录和减少输入记录之间的关系是什么,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47511729/
请看一下我的代码。 int main () { Program* allcommand = new Program; allcommand->addCommand("add", new
因此,当我遇到调试断言时,我正在编写代码。现在我很想知道为什么这段代码不起作用: for(Model::MeshMap::iterator it = obj1->GetMeshes().begin()
这是我上一个问题的延续 Group, Sum byType then get diff using Java streams . 按照建议,我应该作为单独的线程发布,而不是更新原始线程。 因此,通过我
我正在实现一些非常适合 map 的代码。但是,我要迭代的列表中有大量对象,所以我的问题是哪种方法是解决此问题的最佳方法: var stuff = $.map(listOfMyObjects, some
我正在尝试创建一个包含不同类的成员函数指针的映射。成员函数都具有相同的签名。为了做到这一点,我所有的类都继承了一个 Object 类,它只有默认构造函数、虚拟析构函数和一个虚拟 ToString()
这个问题在这里已经有了答案: 关闭 11 年前。 Possible Duplicate: how do you make a heterogeneous boost::map? 有可能在 C++ 中
我有一个 Mysql 查询,请检查以下内容: SELECT `tbl_classSubjects`.`classID` , `tbl_classSubjects`.`sectionID` , `tbl
抱歉,这可能是一个基本问题。 JNA直接映射和接口(interface)映射有什么区别? 我的解释是否正确: 直接映射 : 直接使用库对象(如 Java 中的静态 main) 接口(interface
在 Twitter's Scala school collections section ,它们显示了一个带有偏函数作为值的 Map: // timesTwo() was defined earlie
很难说出这里问的是什么。这个问题是模棱两可的、模糊的、不完整的、过于宽泛的或修辞的,无法以目前的形式得到合理的回答。如需帮助澄清这个问题以便重新打开它,visit the help center .
据我了解,从 scala stdlib 声明一个映射并没有将其专门用于原始类型。我要的不是付出装箱/拆箱的代价,而是同时拥有scala map 的接口(interface)。一个明显的选择是使用 tr
如何为这样的 JSON 响应创建对象映射,它只是一个整数数组: [ 565195, 565309, 565261, 565515, 565292, 565281, 566346, 5
是否可以为 DTO 对象创建映射然后查询它们 而不是域?如果不解释为什么? 如果我需要几个 dtos 怎么办? DTos 是只读的 ID 由 NH 自动生成 将来这些 dtos 将设置映射到链接的 d
我有一个返回的函数(常规代码) [words: "one two", row: 23, col: 45] 在 Scala 中,我将上面更改为 Scala Map,但随后我被迫将其声明为 Map[Str
我有一组与 Vanilla 磅蛋糕烘焙相关的数据(200 行),具有 27 个特征,如下所示。标签caketaste是衡量烤蛋糕的好坏程度,由 bad(0) 定义, neutral(1) , good
我有试图映射到新代码的遗留代码。 OLD_PERSON pid sid name age NEW_PERSON pid sid fid age RESOLVE_PERSON pid fid statu
我有一个表,其中一个字段可以指向其他 3 个表之一中的外键,具体取决于鉴别器值是什么(Project、TimeKeep 或 CostCenter。通常这是用子类实现的,我想知道我有什么 注意子类名称与
我有一个类型 [ST s (Int, [Int])] 的绑定(bind)我正在尝试申请runST使用映射到每个元素,如下所示: name :: [ST s (Int, [Int])] --Of Cou
在我正在进行的项目中,我有以下实体:分析师、客户 和承包商。每个都继承自基类 User。 public abstract class User { public virtual int Id
我想知道是否可以在 Vim 中创建一个映射(对于普通模式),允许用户在映射执行之前输入。 我想为我最常用的 grep 命令创建一个快捷方式的映射。我希望命令允许输入我正在搜索的内容,然后在输入时执行。
我是一名优秀的程序员,十分优秀!