diff --git a/.idea/uiDesigner.xml b/.idea/uiDesigner.xml
new file mode 100644
index 0000000..e96534f
--- /dev/null
+++ b/.idea/uiDesigner.xml
@@ -0,0 +1,124 @@
+
+
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+
+
+
+ -
+
+
+
+
+
+ -
+
+
+
+
+
+ -
+
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+
+
+ -
+
+
+ -
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/workspace.xml b/.idea/workspace.xml
index e128e88..4da4345 100644
--- a/.idea/workspace.xml
+++ b/.idea/workspace.xml
@@ -2,9 +2,12 @@
+
+
+
+
-
@@ -17,11 +20,11 @@
-
+
-
-
+
+
@@ -30,8 +33,8 @@
-
-
+
+
@@ -39,11 +42,11 @@
-
+
-
+
@@ -51,6 +54,16 @@
+
+
+
+
+
+
+
+
+
+
@@ -124,8 +137,11 @@
@@ -171,10 +187,9 @@
+
-
-
@@ -237,6 +252,7 @@
+
@@ -246,6 +262,11 @@
+
+
+
+
+
@@ -258,7 +279,7 @@
-
+
@@ -266,6 +287,25 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -280,31 +320,6 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
@@ -466,19 +481,19 @@
-
-
-
-
-
+
+
+
+
+
-
-
-
-
-
+
+
+
+
+
@@ -506,7 +521,9 @@
-
+
+
+
1521904777876
@@ -550,7 +567,14 @@
1524058535951
-
+
+ 1524061191596
+
+
+
+ 1524061191596
+
+
@@ -586,7 +610,7 @@
-
+
@@ -594,30 +618,30 @@
+
-
+
-
+
-
+
-
@@ -634,13 +658,88 @@
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -936,11 +1035,22 @@
-
+
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -963,53 +1073,74 @@
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/pom.xml b/pom.xml
index 6137ba9..09f4d8a 100644
--- a/pom.xml
+++ b/pom.xml
@@ -4,7 +4,7 @@
com.fjy.hadoop
hadoopstudy
- 0.3
+ 0.4
jar
hadoopstudy
diff --git a/src/main/java/com/fjy/hadoop/mapreduce/WordCountPartitionerApp.java b/src/main/java/com/fjy/hadoop/mapreduce/WordCountPartitionerApp.java
new file mode 100644
index 0000000..1919eaa
--- /dev/null
+++ b/src/main/java/com/fjy/hadoop/mapreduce/WordCountPartitionerApp.java
@@ -0,0 +1,158 @@
+package com.fjy.hadoop.mapreduce;
+
+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.Partitioner;
+import org.apache.hadoop.mapreduce.Reducer;
+import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
+import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;
+
+import java.io.IOException;
+
+/**
+ * 使用MapReduce开发Partitioner组件应用
+ * @author F嘉阳
+ * @date 2018-04-20
+ */
+public class WordCountPartitionerApp {
+ /**
+ * Map:读取输入文件
+ * Text:类似字符串
+ */
+ public static class MyMapper extends Mapper {
+
+ LongWritable one = new LongWritable(1);
+
+ /**
+ * @param key 偏移量
+ * @param value 每行的字符串
+ * @param context 上下文
+ * @throws IOException
+ * @throws InterruptedException
+ */
+ @Override
+ protected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {
+ /*super.map(key, value, context);*/
+
+ //接收到每一行数据
+ String line = value.toString();
+
+ String[] words = line.split(" ");//以空格分隔
+
+ //每一个空格是一个手机品牌,另一个是销售数量
+ context.write(new Text(words[0]), new LongWritable(Long.parseLong(words[1])));
+
+ }
+ }
+
+ /**
+ * Reduce 归并操作
+ * LongWritable:文本出现的次数/求和后的次数
+ */
+ public static class MyReducer extends Reducer {
+ /**
+ * @param key
+ * @param values 相同偏移量的集合
+ * @param context
+ * @throws IOException
+ * @throws InterruptedException
+ */
+ @Override
+ protected void reduce(Text key, Iterable values, Context context) throws IOException, InterruptedException {
+ //super.reduce(key, values, context);
+
+ long sum = 0;
+
+ for (LongWritable value : values) {
+ //求key出现的次数和总和
+ sum += value.get();
+ }
+ //统计结果的输出
+ context.write(key, new LongWritable(sum));
+
+ }
+ }
+
+ /**
+ * Partitioner处理类
+ */
+ public static class MyPartitioner extends Partitioner{
+ @Override
+ public int getPartition(Text key, LongWritable value, int i) {
+
+ if ("xiaomi".equals(key.toString())) {
+ return 0;//若为xiaomi则交由0 ReduceTask处理
+ }
+ if ("huawei".equals(key.toString())) {
+ return 1;//若为huawei则交由1 ReduceTask处理
+ }
+ if ("iphone".equals(key.toString())) {
+ return 2;//若为iphone则交由2 ReduceTask处理
+ }
+
+ return 3;//若为其他,则交由3 ReduceTask处理
+ }
+ }
+
+ /**
+ * 定义Driver,封装MapReduce作业的所有信息
+ */
+ public static void main(String[] args) throws Exception {
+
+ //创建Configuration
+ Configuration configuration = new Configuration();
+
+ //清理已存在的输出目录
+ Path outputPath = new Path(args[1]);
+ FileSystem fileSystem = FileSystem.get(configuration);
+ if (fileSystem.exists(outputPath)){
+ fileSystem.delete(outputPath);
+ System.out.println("The exist files had been deleted!");
+ }
+
+ //创建作业
+ Job job = Job.getInstance(configuration, "wordcount");
+
+ //设置作业的主类
+ job.setJarByClass(WordCountPartitionerApp.class);
+
+ //作业处理的输入路径
+ FileInputFormat.setInputPaths(job, new Path(args[0]));
+
+ //设置map相关参数
+ job.setMapperClass(MyMapper.class);
+
+ //设置map输出的key的类型
+ job.setMapOutputKeyClass(Text.class);
+
+ //设置map输出的value的类型
+ job.setMapOutputValueClass(LongWritable.class);
+
+ //设置Reduce相关参数
+ job.setReducerClass(MyReducer.class);
+ job.setOutputKeyClass(Text.class);
+ job.setOutputValueClass(LongWritable.class);
+
+ //设置job的Partition
+ job.setPartitionerClass(MyPartitioner.class);
+ //设置四个reducer,每个分区一个,否则Partitioner配置不生效
+ job.setNumReduceTasks(4);
+
+ //设置作业处理输出结果的输出路径
+ FileOutputFormat.setOutputPath(job, new Path(args[1]));
+
+ //作业提交
+ job.waitForCompletion(true);
+
+ //作业完成后退出
+ System.exit(job.waitForCompletion(true) ? 0 : 1);
+
+ }
+
+
+}