title: How to recursively aggregate Treelike(hierarchical) data using Spark?
body: <p>Given a dataset representing a Treelike hierarchical structure e.g.:</p>
  
  <pre><code>+-------+--------+
  |childId|parentId|
  +-------+--------+
  |      1|       0|
  |      2|       1|
  |      3|       1|
  |      4|       2|
  |      5|       2|
  |      6|       2|
  |      7|       3|
  |      8|       3|
  |      9|       3|
  |     10|       4|
  +-------+--------+
  </code></pre>
  
  <p>How can it be aggregated as follows using <code>Spark</code>? So that, for each node of the Tree, all its children, grand-children and so on(till leaves) are can be aggregated:</p>
  
  <pre><code>+--------+--------------------+-----+
  |parentId|            children|count|
  +--------+--------------------+-----+
  |       1|[15, 9, 16, 2, 17...|   16|
  |       3|[15, 9, 16, 17, 7...|    7|
  |       4|    [12, 13, 10, 11]|    4|
  |       7|    [15, 16, 17, 14]|    4|
  |       2|[12, 13, 5, 6, 10...|    7|
  |       0|[15, 9, 1, 16, 2,...|   17|
  +--------+--------------------+-----+
  </code></pre>
  
  <p>A sample data file can be found <a href="https://github.com/newroyker/SparkTreeApp/blob/master/data/tree/edges.csv" rel="nofollow noreferrer">here</a>.</p>