Depth in tree structure in BigQuery My data looks like the following:
| child_id | parent_id |
|    10    |    Null   |
|    13    |     10    |
|    15    |     13    |
|    11    |     10    |
|    16    |     11    |
|    19    |     15    |

This can be seen as a tree. I now want to determine the depth of each child_id. So the example should be:
| child_id | parent_id |  depth  |
|    10    |    Null   |    0    |
|    13    |     10    |    1    |
|    15    |     13    |    2    |
|    11    |     10    |    1    |
|    16    |     11    |    2    |
|    19    |     15    |    3    |

I want to solve this in BigQuery; I am unsure how though as I don't think one can easily work with recursion. Maybe passing it to a UDF somehow could be a reasonable approach.

I just wrote a query for that, using the just released "full hacker news dataset on BigQuery".
The problem here is that some comments point to the parent story, while other comments post to parent comments, and searching the original story through them is hard (as this is a recursive operation). Solved via:
  SELECT p0.id, s.id, s.title, level
  FROM (
    SELECT p0.id, p0.parent, p2.id, p3.id, p4.id, COALESCE(p7.parent, p6.parent, p5.parent, p4.parent, p3.parent, p2.parent, p1.parent, p0.parent) story_id,
GREATEST(IF(p7.parent IS null, -1, 7), IF(p6.parent IS null, -1, 6), IF(p5.parent IS null, -1, 5), IF(p4.parent IS null, -1, 4), IF(p3.parent IS null, -1, 3),
IF(p2.parent IS null, -1, 2), IF(p1.parent IS null, -1, 1), 0) level
    FROM    [fh-bigquery:hackernews.comments] p0
    LEFT JOIN EACH [fh-bigquery:hackernews.comments] p1 ON p1.id=p0.parent
    LEFT JOIN EACH [fh-bigquery:hackernews.comments] p2 ON p2.id=p1.parent
    LEFT JOIN EACH [fh-bigquery:hackernews.comments] p3 ON p3.id=p2.parent
    LEFT JOIN EACH [fh-bigquery:hackernews.comments] p4 ON p4.id=p3.parent
    LEFT JOIN EACH [fh-bigquery:hackernews.comments] p5 ON p5.id=p4.parent
    LEFT JOIN EACH [fh-bigquery:hackernews.comments] p6 ON p6.id=p5.parent
    LEFT JOIN EACH [fh-bigquery:hackernews.comments] p7 ON p7.id=p6.parent
    HAVING level=0
    LIMIT 100
  ) a
  LEFT JOIN EACH [fh-bigquery:hackernews.stories] s
  ON s.id=a.story_id

(having so many left joins consumes a lot of resources, so to run it massively I would look for a different strategy)
https://news.ycombinator.com/item?id=10440502