In the current implementation, both SparkMapRecordHandler and SparkReduceRecorderHandler takes only one result collector, which limits that the corresponding map or reduce task can have only one child. It's very comment in multi-insert queries where a map/reduce task has more than one children. A query like the following has two map tasks as parents:
It's possible in the future an optimation may be implemented so that a map work is followed by two reduce works and then connected to a union work.
Thus, we should take this as a general case. Tez is currently providing a collector for each child operator in the map-side or reduce side operator tree. We can take Tez as a reference.
Spark currently doesn't have a tranformation that supports mutliple output datasets from a single input dataset (
SPARK-3622). This is a workaround for this gap.
Likely this is a big change and subtasks are possible.