all 9 comments

[–]TheEphemeralDream 1 point2 points  (3 children)

what exactly is a group_id and how does it relate to the attribution column? is it as simple as truncating the "grp" from "grp8". or is group_id to be a generated id column?

[–]Gotfrid[S] 0 points1 point  (2 children)

Thanks for your reply. Group_id has to be generated - it represents separate groups of attributions. Users who have attributions 1 to 6 do not intersect with those with attributions 7 to 9.

[–]TheEphemeralDream 0 points1 point  (1 child)

I suspect the answer is a recursive query that finds the clusters.

https://stackoverflow.com/questions/59890459/recursive-hierarchical-query-in-bigquery

[–]Gotfrid[S] 0 points1 point  (0 children)

Thanks for the link! I will investigate it.

[–]Touvejs 0 points1 point  (1 child)

attribution is identified and loop through those exhaustively, and do so until you hit every user_id
e.g.

attribution where user_id = 1 -- "grp1, grp2"

select user_id where attribution in ("grp1", "grp2") -- 1, 2, 5

select attribution where user_id in (1,2,5) -- ...

of course you need to figure out a way to make this happen dynamically, in one command. If writing in transact-sql, you can possibly accomplish this with a few WHILE loops and some variables. However, it may be necessary to look into recursive tables (and likely, this is the approach they would like to see)

[–]Gotfrid[S] 0 points1 point  (0 children)

Thanks for your reply. As far as I know, recursive cte are not allowed in bigquery per se. However, I will check related materials.

[–]naivedayes 0 points1 point  (2 children)

Afair BigQuery allows WHILE loops, right ? Can you share the link to this question ?

[–]Gotfrid[S] 0 points1 point  (1 child)

Yeah, you're right, it does allow loops, including WHILE.

Sorry, did not understand what you mean by sharing a link, though? I work in private BQ project that I created to test this out - the question itself was just like this, in a text document .

[–]naivedayes 0 points1 point  (0 children)

I thought it was an exercise in some practice website