- 阅读权限
- 255
- 威望
- 1 级
- 论坛币
- 49635 个
- 通用积分
- 55.6937
- 学术水平
- 370 点
- 热心指数
- 273 点
- 信用等级
- 335 点
- 经验
- 57805 点
- 帖子
- 4005
- 精华
- 21
- 在线时间
- 582 小时
- 注册时间
- 2005-5-8
- 最后登录
- 2023-11-26
|
|
- The following example divides a PCollection into percentile groups.
- // Provide an int value with the desired number of result partitions, and a PartitionFn that represents the partitioning function.
- // In this example, we define the PartitionFn in-line.
- // Returns a PCollectionList containing each of the resulting partitions as individual PCollection objects.
- PCollection<Student> students = ...;
- // Split students up into 10 partitions, by percentile:
- PCollectionList<Student> studentsByPercentile =
- students.apply(Partition.of(10, new PartitionFn<Student>() {
- public int partitionFor(Student student, int numPartitions) {
- return student.getPercentile() // 0..99
- * numPartitions / 100;
- }}));
- // You can extract each partition from the PCollectionList using the get method, as follows:
- PCollection<Student> fortiethPercentile = studentsByPercentile.get(4);
复制代码
|
|