job.setMapperClass(EarthQuakesPerDateMapper.class);
job.setReducerClass(EarthQuakesPerDateReducer.class);
job.setOutputKeyClass(Text.class);
job.setOutputValueClass(IntWritable.class);
System.exit(job.waitForCompletion(true) ? 0 : 1);
}
}
在linux上执行hadoop:
$> export HADOOP_CLASSPATH=lib/opencsv-2.3.jar
$> hadoop jar hadoop.jar in out
在程序所在目录定义一个子目录in,把刚才所下载的cvs文件放到in目录下。
in就是程序数据的输入目录,out是输出目录,注意这个out文件夹是程序建立的,不可以手动建立。
运行是会看到:
11/09/05 08:47:26 INFO jvm.JvmMetrics: Initializing JVM Metrics with processName=JobTracker, sessionId=
11/09/05 08:47:26 WARN mapred.JobClient: Use GenericOptionsParser for parsing the arguments. Applications should implement Tool for the same.
11/09/05 08:47:26 INFO input.FileInputFormat: Total input paths to process : 1
11/09/05 08:47:26 INFO mapred.JobClient: Running job: job_local_0001
11/09/05 08:47:26 INFO input.FileInputFormat: Total input paths to process : 1
11/09/05 08:47:26 INFO mapred.MapTask: io.sort.mb = 100
11/09/05 08:47:27 INFO mapred.MapTask: data buffer = 79691776/99614720
11/09/05 08:47:27 INFO mapred.MapTask: record buffer = 262144/327680
11/09/05 08:47:27 INFO mapred.JobClient: map 0% reduce 0%
11/09/05 08:47:28 INFO mapred.MapTask: Starting flush of map output
11/09/05 08:47:28 INFO mapred.MapTask: Finished spill 0
11/09/05 08:47:28 INFO mapred.TaskRunner: Task:attempt_local_0001_m_000000_0 is done. And is in the process of commiting
11/09/05 08:47:28 INFO mapred.LocalJobRunner:
11/09/05 08:47:28 INFO mapred.TaskRunner: Task 'attempt_local_0001_m_000000_0' done.
11/09/05 08:47:29 INFO mapred.LocalJobRunner:
11/09/05 08:47:29 INFO mapred.Merger: Merging 1 sorted segments
11/09/05 08:47:29 INFO mapred.Merger: Down to the last merge-pass, with 1 segments left of total size: 97887 bytes
11/09/05 08:47:29 INFO mapred.LocalJobRunner:
11/09/05 08:47:29 INFO mapred.TaskRunner: Task:attempt_local_0001_r_000000_0 is done. And is in the process of commiting
11/09/05 08:47:29 INFO mapred.LocalJobRunner:
11/09/05 08:47:29 INFO mapred.TaskRunner: Task attempt_local_0001_r_000000_0 is allowed to commit now
11/09/05 08:47:29 INFO output.FileOutputCommitter: Saved output of task 'attempt_local_0001_r_000000_0' to out1
11/09/05 08:47:29 INFO mapred.LocalJobRunner: reduce > reduce
11/09/05 08:47:29 INFO mapred.TaskRunner: Task 'attempt_local_0001_r_000000_0' done.
11/09/05 08:47:29 INFO mapred.JobClient: map 100% reduce 100%
11/09/05 08:47:29 INFO mapred.JobClient: Job complete: job_local_0001
11/09/05 08:47:29 INFO mapred.JobClient: Counters: 12
11/09/05 08:47:29 INFO mapred.JobClient: FileSystemCounters
11/09/05 08:47:29 INFO mapred.JobClient: FILE_BYTES_READ=11961631
11/09/05 08:47:29 INFO mapred.JobClient: FILE_BYTES_WRITTEN=9370383
11/09/05 08:47:29 INFO mapred.JobClient: Map-Reduce Framework
11/09/05 08:47:29 INFO mapred.JobClient: Reduce input groups=142
11/09/05 08:47:29 INFO mapred.JobClient: Combine output records=0
11/09/05 08:47:29 INFO mapred.JobClient: Map input records=5639
11/09/05 08:47:29 INFO mapred.JobClient: Reduce shuffle bytes=0
11/09/05 08:47:29 INFO mapred.JobClient: Reduce output records=142
11/09/05 08:47:29 INFO mapred.JobClient: Spilled Records=11274
11/09/05 08:47:29 INFO mapred.JobClient: Map output bytes=86611
11/09/05 08:47:29 INFO mapred.JobClient: Combine input records=0
11/09/05 08:47:29 INFO mapred.JobClient: Map output records=5637
11/09/05 08:47:29 INFO mapred.JobClient: Reduce input records=5637
运行完成后:
cd到out目录下,会看到一个part-r-00000文件。
输入命令:cat part-r-00000
可以看到hadoopjob的运行结果。