Github user davies commented on a diff in the pull request:
https://github.com/apache/spark/pull/3193#discussion_r20256368
--- Diff: python/pyspark/rdd.py ---
@@ -316,6 +316,34 @@ def sample(self, withReplacement, fraction, seed=None):
assert fraction >= 0.0, "Negative fraction value: %s" % fraction
return self.mapPartitionsWithIndex(RDDSampler(withReplacement,
fraction, seed).func, True)
+ def randomSplit(self, weights, seed=None):
+ """
+ Randomly splits this RDD with the provided weights.
+
+ :param weights: weights for splits, will be normalized if they
don't sum to 1
+ :param seed: random seed
+ :return: split RDDs in an list
+
+ >>> rdd = sc.parallelize(range(10), 1)
+ >>> rdd1, rdd2, rdd3 = rdd.randomSplit([0.4, 0.6, 1.0], 11)
+ >>> rdd1.collect()
+ [3, 6]
+ >>> rdd2.collect()
+ [0, 5, 7]
+ >>> rdd3.collect()
+ [1, 2, 4, 8, 9]
+ """
+ ser = BatchedSerializer(PickleSerializer(), 1)
--- End diff --
To simplify the serialization, we change to always use batched serializer
(auto batched or with fixed size). Comparing to un-batched, batched with only
one in it it dose have some overhead, the overhead will similar to those of
Array[Byte] in JVM.
Another approach is to implement the random split in Python, then we do not
need to worry about the batch size.
I think we could have a correct implementation first, we can always
optimize it if there is real big performance difference.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]