patition类结构apache
2. HashPartitioner是mapreduce的默认partitioner。计算方法是缓存
which reducer=(key.hashCode() & Integer.MAX_VALUE) % numReduceTasks,获得当前的目的reducer。app
3. BinaryPatitioner继承于Partitioner< BinaryComparable ,V>,是Partitioner的偏特化子类。该类提供leftOffset和rightOffset,在计算which reducer时仅对键值K的[rightOffset,leftOffset]这个区间取hash。dom
Which reducer=(hash & Integer.MAX_VALUE) % numReduceTasks分布式
4. KeyFieldBasedPartitioner也是基于hash的个partitioner。和BinaryPatitioner不一样,它提供了多个区间用于计算hash。当区间数为0时KeyFieldBasedPartitioner退化成HashPartitioner。oop
$HADOOP_HOME/bin/hadoop streaming \url
-D stream.map.output.field.separator=. \spa
-D stream.num.map.output.key.fields=4 \对象
-D map.output.key.field.separator=. \ #map输出分隔符设为“.”blog
-D num.key.fields.for.partition=2 \ #将key分隔出来的前两个部分而不是整个key用于Partitioner作partition
-input /user/test/input -output /user/test/output \
-mapper “mymapper.sh” -reducer “ myreducer.sh” \
-partitioner org.apache.hadoop.mapred.lib.KeyFieldBasedPartitioner \ #使用KeyFieldBasedPartitioner
-file /home/work/mymapper.sh \
-file /home/work/myreducer.sh \
-jobconf mapred.job.name=”key-partition-demo”
5. TotalOrderPartitioner这个类能够实现输出的全排序。不一样于以上3个partitioner,这个类并非基于hash的。在下一节里详细的介绍totalorderpartitioner。
采样类结构图
采样方式对比表:
类名称 |
采样方式 |
构造方法 |
效率 |
特色 |
SplitSampler<K,V> |
对前n个记录进行采样 |
采样总数,划分数 |
最高 |
|
RandomSampler<K,V> |
遍历全部数据,随机采样 |
采样频率,采样总数,划分数 |
最低 |
|
IntervalSampler<K,V> |
固定间隔采样 |
采样频率,划分数 |
中 |
对有序的数据十分适用 |