I just discovered the RDD.zip()
method and I cannot imagine what its contract could possibly be.
I understand what it does, of course. However, it has always been my understanding that
- the order of elements in an RDD is a meaningless concept
- the number of partitions and their sizes is an implementation detail only available to the user for performance tuning
In other words, an RDD is a (multi)set, not a sequence (and, of course, in, e.g., Python one gets AttributeError: 'set' object has no attribute 'zip'
)
What is wrong with my understanding above?
What was the rationale behind this method?
Is it legal outside the trivial context like a.map(f).zip(a)
?
EDIT 1:
- Another crazy method is
zipWithIndex()
, as well as well as the various zipPartitions()
variants.
- Note that
first()
and take()
are not crazy because they are just (non-random) samples of the RDD.
collect()
is also okay - it just converts a set
to a sequence
which is perfectly legit.
EDIT 2: The reply says:
when you compute one RDD from another the order of elements in the new RDD may not correspond to that in the old one.
This appears to imply that even the trivial a.map(f).zip(a)
is not guaranteed to be equivalent to a.map(x => (f(x),x))
. What is the situation when zip()
results are reproducible?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…