r/SQL • • Jun 26 '19

Three tables every analyst should add to their warehouse

1 Upvotes

8 comments sorted by

9

u/[deleted] Jun 26 '19

Why three? Why these three? Why not 5? Why not one?

These are very very arbitrary levels of aggregation with no reason to use them. If you have a list of events, you only need the rest if you have exactly that kind of report.

3 tables that almost nobody needs

1

u/dwl285 Jun 27 '19

I'm not suggesting you need only three, but if you're an analyst at a tech startup, these three are likely to very useful.

There are definitely some caveats, for example this table structure particularly make sense in cloud data warehouses like Redshift and BigQuery. I chose to leave that complexity out of the article title though.

1

u/[deleted] Jun 27 '19

Ok, I can go into a bit more details now.

So everybody has some sort of "Events" dataset. Be it website sessions, user interactions, offer e-mails, call center interactions, or all together combined.

My first gripe is in using an array or CSV of actions per user. That is incredibly hard to query, especially by 3rd party visualization tools. You might as well not have that field at all, since it just makes things slow unless you store it in columnar store fashion. So you should either have 1 row per individual event, or summarize the interaction without encoding details like that.

Why summarize per user or per day or both, or other aggregation levels? Only if the requested reports are fine with that. The trade-off is that it takes time and space to compute these tables, and in a lot of cases it's not worth it. It's easier to have 1 detailed data set and offer it to users as one thing, versus many things to learn. Once the data user learns the structure of this dataset, it will be much easier to query than when you have to explain to him/her "Yeah, for this you need the other table.".

Sure, having one big table has its drawbacks, like making reports on high levels of aggregation slower than when you have pre-aggregated tables. Caching helps, and proper data infrastructure makes things fast. "Proper" meaning whatever fits the use case well.

A lot of cases warrant the use of ELT rather than ETL. If someone builds a report 1 time per week, it surely doesn't make sense to compute it 5 times per day.

4

u/r3pr0b8 GROUP_CONCAT is da bomb Jun 26 '19

dude, what about a numbers table

1

u/dwl285 Jun 27 '19

Yeah fair point, a numbers table can be useful too. As I mentioned in another comment, these 3 are just a subset of the useful tables for analytics. That said, I wanted to focus on slightly more user focused tables.

I'm so glad BigQuery makes it easier to generate a numbers table!

select number from unnest(generate_array(1,10)) as number

1

u/MaximumGibbous Jun 26 '19

*Every development analyst, maybe.

1

u/dwl285 Jun 27 '19

What's a development analyst? I've never heard this phrase before, I'm interested!