当前位置:网站首页>MR-WordCount
MR-WordCount
2022-06-28 05:50:00 【Hill】
pom.xml
<dependencies>
<dependency>
<groupId>org.apache.hadoop</groupId>
<artifactId>hadoop-common</artifactId>
<version>3.2.2</version>
</dependency>
<dependency>
<groupId>org.apache.hadoop</groupId>
<artifactId>hadoop-hdfs</artifactId>
<version>3.2.2</version>
</dependency>
<dependency>
<groupId>org.apache.hadoop</groupId>
<artifactId>hadoop-client</artifactId>
<version>3.2.2</version>
</dependency>
<dependency>
<groupId>org.apache.hadoop</groupId>
<artifactId>hadoop-mapreduce-client-core</artifactId>
<version>3.2.2</version>
</dependency>
</dependencies>
<build>
<plugins>
<!-- Main function entry -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.4</version>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix>lib/</classpathPrefix>
<mainClass>com.mr.demo.wordcount.WordCount</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
<!--jdk Definition -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.0</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
</plugins>
</build>
WordCount.java
MapReduce Programming cases
package com.flink.mr.demo.wordcount;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
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 java.io.IOException;
import java.net.URI;
public class NeoWordCount {
public static class NeoWordCountMapper extends Mapper<LongWritable, Text, Text, LongWritable> {
private final LongWritable ONE = new LongWritable(1);
private final Text outputK = new Text();
@Override
protected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {
for (String s : value.toString().split(" ")) {
outputK.set(s);
context.write(outputK, ONE);
}
}
}
public static class NeoWordCountReducer extends Reducer<Text, LongWritable, Text, LongWritable> {
private final LongWritable outputV = new LongWritable();
@Override
protected void reduce(Text key, Iterable<LongWritable> values, Context context) throws IOException, InterruptedException {
long sum = 0;
for (LongWritable value : values) {
sum += value.get();
}
outputV.set(sum);
context.write(key, outputV);
}
}
public static void main(String[] args) throws Exception {
/*GenericOptionsParser parser = new GenericOptionsParser(args);
Job job = Job.getInstance(parser.getConfiguration());
args = parser.getRemainingArgs();*/
System.setProperty("HADOOP_USER_NAME","bigdata");
Configuration config = new Configuration();
config.set("fs.defaultFS","hdfs://10.1.1.1:9000");
config.set("mapreduce.framework.name","yarn");
config.set("yarn.resourcemanager.hostname","10.1.1.1");
// Cross platform parameters
config.set("mapreduce.app-submission.cross-platform","true");
Job job = Job.getInstance(config);
job.setJar("D:\\bigdata\\mapreduces\\flink-mr.jar");
job.setInputFormatClass(TextInputFormat.class);
job.setOutputFormatClass(TextOutputFormat.class);
job.setMapOutputKeyClass(Text.class);
job.setMapOutputValueClass(LongWritable.class);
job.setOutputKeyClass(Text.class);
job.setOutputKeyClass(LongWritable.class);
job.setMapperClass(NeoWordCountMapper.class);
job.setReducerClass(NeoWordCountReducer.class);
job.setCombinerClass(NeoWordCountReducer.class);
Path inputPath = new Path("/user/bigdata/demo/001/input");
FileInputFormat.setInputPaths(job, inputPath);
Path outputPath = new Path("/user/bigdata/demo/001/output");
FileSystem fs = FileSystem.get(new URI("hdfs://10.1.1.1:9000"),config,"bigdata");
if(fs.exists(outputPath)){
fs.delete(outputPath,true);
}
FileOutputFormat.setOutputPath(job, outputPath);
System.exit(job.waitForCompletion(true) ? 0 : 1);
}
}
Environmental requirements
1. Local packaging forms
D:\bigdata\mapreduces\flink-mr.jar
2.Hadoop Environmental Science
10.1.1.1
3. Document preparation
hdfs://10.1.1.1:9000/user/bigdata/demo/001/input
Upload several files for analysis
4. Run this example , Submit MR Task to cluster
边栏推荐
- 数据中台:数据治理的建设思路以及落地经验
- Gee learning notes 3- export table data
- Install fmpefg
- Data midrange: implementation and summary of AI midrange
- Typescript base type
- Data warehouse: financial / banking theme layer division scheme
- Maskrcnn,fast rcnn, faster rcnn优秀视频
- Flink 窗口机制 (两次等待, 最后兜底)
- To batch add background pictures and color changing effects to videos
- Solution of dam safety automatic monitoring system for medium and small reservoirs
猜你喜欢

The windows environment redis uses AOF persistence and cannot generate an AOF file. After generation, the content of the AOF file cannot be loaded

JS中的链表(含leetcode例题)<持续更新~>

Jdbc的使用

To batch add background pictures and color changing effects to videos

Bidirectional level conversion circuit

Interpretation of cloud native microservice technology trend

jsp连接oracle实现登录注册(简单)

Lenovo hybrid cloud Lenovo xcloud, new enterprise IT service portal

Shutter nestedscrollview sliding folding head pull-down refresh effect

Solution of dam safety automatic monitoring system for medium and small reservoirs
随机推荐
安装 Ffmpefg
Enum
Windows环境Redis使用AOF持久化,无法生成AOF文件,生成后无法加载AOF文件内容
Mysql-16-subquery
jsp连接Oracle实现登录注册
Data middle office: six questions data middle office
Jdbc的使用
ES9023音频解码芯片的工作原理
qtcanpool 知 07:Ribbon
Application of Beidou No.3 short message terminal in dam safety monitoring scheme
1404. number of steps to reduce binary representation to 1
UICollectionViewDiffableDataSource及NSDiffableDataSourceSnapshot使用介绍
阴阳师页面
容量调度绝对值配置队列使用与避坑
TypeScript基础类型
Blog login box
Relevant implementation records of CSI and local disk
Introduction to uicollectionviewdiffabledatasource and nsdiffabledatasourcesnapshot
YYGH-BUG-02
YYGH-8-预约挂号