SPARK-3580: New public method for RDD's to have consistent way of obtain...

...ing the number of RDD partitions across languages.


minor style comment but you can just write this like:

```
def getNumPartitions: Int = partitions.size
```