It was the first thing that I tried in the playground, since it was top of mind, but unfortunately it doesn't seem like the language supports recursive queries (yet). https://github.com/PRQL/prql/issues/407
It was the first thing that I tried in the playground, since it was top of mind, but unfortunately it doesn't seem like the language supports recursive queries (yet). https://github.com/PRQL/prql/issues/407
1. Build the JSON from the bottom up starting at the deepest path.
2. At each step, handle two cases: a) build the parent of the working set, and b) collect any sibling paths at the same depth.
3. The last step aggregates all children together since all paths descend from '/'.
Solution: https://www.db-fiddle.com/f/qTcG5BUjM8GzuzBfHamnVJ/4
There was a fair bit of trickiness. I used a CTE in the recursive step to reference the recursive table multiple times and to enable aggregation in the recursive step. I used a few helper functions for my own sanity.