When I worked with BigQuery, I used this article to unnest repeated records: https://help.looker.com/hc/en-us/articles/360023638874-Nested-Data-in-BigQuery-Repeated-Records-
When working with Snowflake, however, I realised I’m missing a similar pattern for ARRAYs.
I have a table <categories> and then <products>. Product table can have multiple categories.
So far I would have to use another view and another join from a junction table product_categories but I wanted to have something easier.
I added a new column “category_ids” to the products and then used the following code:
explore: categories {
join: products {
type: left_outer
relationship: many_to_many
sql_on: 1 = 1, LATERAL FLATTEN(${products.category_ids}) c ;;
sql_where: c.value = ${categories.category_id} ;;
}
}
This is from the point of view of a category. It basically creates a CROSS JOIN and SQL_WHERE changes it into an INNER.
This topic helped me down this path, but this medium article is what helped the most.
I can't believe that this isn’t higher traffic.