I am wondering whether a recursive UDF function in BigQuery is the right solution to what i'm doing. But first, is it possible to run a query from inside the UDF?
I see a similar question here: BigQuery : is it possible to execute another query inside an UDF? but the solution seems to be a workaround that executes straight SQL. In my case, I might have to call the UDF repeatedly/recursively without knowing in advance the number of steps (say 3-7 steps).
It's a simple use-case of building a relationship graph over user-name entries in a table, with X degrees of separation, where X will be supplied by the end-user as an argument. My guess is recursive-style UDF would work well, but is it possible?
****EDIT: More detail on the use-case:**
Consider a table with transaction data, which contains the counterparts in each row, along with some other information:
Buyer, Seller
Bob->Alice
Bob->Carol
Bob->John
John-Peter
John-Sam
Bob->Mary
Suppose I want to visualize the relationship of Bob with his counterparts, with 1 degree of separation (i.e. also showing each counterpart's relationships 1 step removed from Bob). I want to use the force graph like this one here: D3 Force-Collapsible Graph
This graph requires a .JSON file with the following structure:
{
"name": "Bob", "size":5000,
"children":
[
{"name":"Alice","size":3000},
{"name":"Carol","size":3000},
{"name":"John","size":3000,
"children":[
{"name":"Peter","size":3000},
{"name":"Sam","size":3000}
]},
{"name":"Mary","size":3000}
]
}
so, with 1 degree of separation, Bob has 4 children, and out of those, John has 2 children. This can go deeper with X degrees of separation, ideally with X provided by the user, but practically can also be hard-coded to say level 3 or 5.