如何获取分区中的元素数? [英] How to get the number of elements in partition?
本文介绍了如何获取分区中的元素数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在给定分区ID的情况下,是否有任何方法可以获取spark RDD分区中的元素数?无需扫描整个分区.
Is there any way to get the number of elements in a spark RDD partition, given the partition ID? Without scanning the entire partition.
类似这样的东西:
Rdd.partitions().get(index).size()
除非我没有看到用于Spark的API.有任何想法吗?解决方法?
Except I don't see such an API for spark. Any ideas? workarounds?
谢谢
推荐答案
以下内容为您提供了一个新的RDD,其中包含的元素是每个分区的大小:
The following gives you a new RDD with elements that are the sizes of each partition:
rdd.mapPartitions(iter => Array(iter.size).iterator, true)
这篇关于如何获取分区中的元素数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文