Hey all, I'm trying to do some ID resolution on to...
# support
e
Hey all, I'm trying to do some ID resolution on top of the
tracks
table where I want create an ID graph of
anonymous_id
and
user_id
. I want to - • Stitch pre-login and post-login events together • Users can login from various devices so I want to stitch multiple devices belonging to a user together as well To do this, I was trying the dbt-id-stitching package and tried using it on a dummy dataset on Snowflake. I've not been able to get it to work though so need another pair of eyes to confirm if I'm doing something wrong here. I have
anonymous_id
and
user_id
coming in from the tracks table like so in a table called
id_mapping
Copy code
ANONYMOUS_ID,   EMAIL
1,			 	abc@gmail.com
1,			 	a@gmail.com
1,			 	null
2,			 	a@gmail.com
3,			 	b@gmail.com
3,			 	null
4,			 	c@gmail.com
I'm using the
1.3.2
version of the package with the following variables.
Copy code
vars:
  id-columns: ('anonymous_id', 'email')
  schemas-to-include: ('id_stitching')
  tables-to-include: ('id_mapping')
I ran the command
Copy code
dbt run --full-refresh --select queries edges check_edges
Here is what the queries table looks like after it
Copy code
SELECT DISTINCT EMAIL::TEXT AS node_a, 'EMAIL' AS node_a_label, ANONYMOUS_ID::TEXT AS node_b, 'ANONYMOUS_ID' AS node_b_label FROM DEV.ID_STITCHING.ID_MAPPING WHERE COALESCE(EMAIL::TEXT, '') != '' AND COALESCE(ANONYMOUS_ID::TEXT, '') != ''
Here is the output of the edges table
Copy code
RUDDER_ID,	ORIGINAL_RUDDER_ID,	NODE_A,			NODE_A_LABEL,	NODE_B,	 NODE_B_LABEL,	NODE_TIMESTAMP
1,			1,					abc@gmail.com,	EMAIL,			1,		 ANONYMOUS_ID,	2023-12-02 07:14:25.834 +0000
2,			2,					a@gmail.com,	EMAIL,			1,		 ANONYMOUS_ID,	2023-12-02 07:14:25.834 +0000
3,			3,					null,			EMAIL,			1,		 ANONYMOUS_ID,	2023-12-02 07:14:25.834 +0000
4,			4,					a@gmail.com,	EMAIL,			2,		 ANONYMOUS_ID,	2023-12-02 07:14:25.834 +0000
5,			5,					b@gmail.com,	EMAIL,			3,		 ANONYMOUS_ID,	2023-12-02 07:14:25.834 +0000
6,			6,					null,			EMAIL,			3,		 ANONYMOUS_ID,	2023-12-02 07:14:25.834 +0000
7,			7,					c@gmail.com,	EMAIL,			4,		 ANONYMOUS_ID,	2023-12-02 07:14:25.834 +0000
check_edges says consolidation_needed = false, so this it the final output. As can be seen above, no ids were stitched together. Is something wrong with my configs or is this use case not the right one for this package?
m
Hey There! 👋 Your message has been received by the RudderStack team. Our standard customer support hours are 9-6 PM EST, but we will forward this request to your Technical Account Manager, and they will get back to you shortly. Please use the thread for any additional comments.
f
Hi @early-table-25049 you can do this with pure SQL, though you need recursive CTE. https://www.mitzu.io/post/identifying-users-in-the-data-warehouse Here is a post about it.
In case DBT stitching wouldn’t work
g
Thanks for the question! I actually had the same problem. @future-caravan-11179 How is this different to dbt approach? And which one is easier to maintain?
and neither dbt nor recursive CTE approach can be used with bigquery? For free users...
f
Ahh, true. Thanks for highlighting. BigQuery has recursive CTEs only in a paid version. What a shame
g
@future-caravan-11179 do you know if dbt can be used with bigquery to do the stitching on a free version?
f
I dont know that, but i will check that later… i am also very curious
It seems dbt-id-stitching doesnt user recursive ctes, but you need to execute the model multiple times . 6 or 7 times should be sufficient. https://github.com/rudderlabs/dbt-id-stitching
So tldr, it should be possible to use in the free big query
g
Thanks @future-caravan-11179. I saw in the dbt-rudderstack doc that only works for postgres, snowflake but no mentioning of bigquery.... Is this what you were referring too?
f
Based on the code it should work with BigQuery. I will investigate it further, next week.
✅ 1
e
Thanks @future-caravan-11179, this is helpful. Curious to understand how compute intensive is the workload that you've shared in the blog post? The dbt-id-stitching package has provision for converging connected components by repeatedly running the
edges
model, however it did not work in my case. My initial thoughts on why this did not work is that the package doesn't seem to be considering bi-directional edges while computing the connected components
f
Typically bidirectional graphs tend to work. Our recursive sql approach is similar to what dbt-stitching (imho) the only difference that we do it in go, and it is a sql query that can be debugged.
c
Following - tried that package a while ago and didn’t work with bigquery.
f
How expensive is BQ ? I often find myself not paying $2 per and have missing features. 😄
g
Hello everyone. So not worth trying dbt stitching with bigquery then? And when you say @future-caravan-11179 paid version, are you referring to bigquery or rudderstack? I think bigquery is free - just pay per compute no?
f
You need to enable payment for extra features like (Recursive CTE and Scheduled jobs). You will still pay per compute only, but you need to give them your credit card details…
I will try it now, we have a free version as well… give me a second 🙂.
🙌 1
Copy code
WITH RECURSIVE
  CTE_1 AS (
    (SELECT 1 AS iteration UNION ALL SELECT 1 AS iteration)
    UNION ALL
    SELECT iteration + 1 AS iteration FROM CTE_1 WHERE iteration < 3
  )
SELECT iteration FROM CTE_1
ORDER BY 1 ASC
this query worked for me! 🚀
So this SQL should be fine as well… from our blog https://www.mitzu.io/post/identifying-users-in-the-data-warehouse
Copy code
CREATE TABLE some_schema.user_aliases as 
WITH RECURSIVE 
edges as (
  select 
    anonymous_id as a,
    coalesce(email, anonymous_id) as b 
  from page_visits
  union all
  select 
    contat_id as a,
    email as b
  from hubspot_contacts -- extending with Hubspot
  union all
  select 
    customer_id as a,
    email as b
  from stripe_customers  -- extending with Stripe
),

bidirectional as (
  select a,
    b
  from edges
  union all
  select b as a,
    a as b
  from edges
),

walks AS (
  SELECT 
    a as a,
    a as b,
    1 as depth
  FROM bidirectional
  UNION
  SELECT w.a,
    e.b,
    depth + 1 as depth
  FROM walks w
    JOIN bidirectional e ON w.b = e.a
    and not (
      e.a = w.a
      and e.b = w.b
    )
    and not (
      e.b = w.a
      and e.a = w.b
    )
  -- Termination condition
  where depth < 10 
)

select 
  min(b) merged_id,
  a as alias
from walks
group by 2
g
Great to hear @future-caravan-11179! I will try this tomorrow and let you know. Have you also maybe tried dbt stitching on bigquery? I am a bit unsure which option is the way to go...
f
I haven’t, that should work on bigquery. But i am not sure how good that solution is based on the feedback here.