spotify/crunch-lib — pull request #8 by DavW (2014-11-28 15:31:23+00:00)
Title: MapFns.detach(...), to explicitly prevent Avro object reuse in reducers

When writing MapFns operating on PGroupedTables, you operate on an Iterable of your
value type. In some serialization formats (such as Avro), this will actually give
you the same object multiple times with different data, which breaks if you want
to add all the objects to a collection and output that without explicitly cloning
all the records.

This patch adds a MapFns.detach(MapFn, PType) method which wraps a MapFn so that
it is passed an Iterable of 'detached' objects created by calling getDetachedValue
on the provided PType and incoming object. The PType will be initialized in the
MapFn's initialize step, so you can just pass in PTypes obtained directly from
Avros or PTypeFamilys