Hey everyone, basic data engineering question: Wou...
# troubleshooting
s
Hey everyone, basic data engineering question: Would anyone know how to translate a type 2 warehouse table (1 entry has an array of historical values with a "changed at") into a monthly value with the actual value at that time? I'm trying to wrap my head around it with SQL
a
There are two methods really: 1. Date join calendar date between the start and end date of the dim. 2. Surrogate key join, which is often the same as above in how the key is created and populated to the fact table, but then when you join from dim to fact, it's an equijoin (faster and safer than a range join at runtime).
I like to create surrogate keys as a concatenation of the business key and the start date as a stringified int with a delimiter. This makes for a deterministic key that's meaningful for humans and easy to debug.
Probably others have approaches which work well for them, but that's generally my approach personally.
s
Awesome, thank you so much! I'll have to look up how to operate them both
Surrogate key joined worked! For posterity, here is the tutorial I followed: https://www.sisense.com/blog/when-and-how-to-use-surrogate-keys/