You Don’t Write The Query
your model, the semantic layer that translates a click into SQL, and the person who never sees either. The semantic layer is not a courtesy — it is the only thing standing between what your model permits and what a stranger can accidentally ask it.
Chapters 1 through 23 made a model correct and made it survive production load. This chapter is about the moment after that: someone opens a BI tool, drags three fields onto a canvas, and gets a number. They never see your DDL, never read your SCD policy, and never open the query they just ran.
There are three parties in that moment, not two: your model, the BI tool’s semantic or metadata layer sitting between you and them, and the person dragging the fields. Naming the middle party matters — it turns "the reader misused the data" from an excuse into a design failure. Your model does not answer the question. It constrains the set of SQL the tool is allowed to generate on your behalf.
Meet Marchwood Plant & Tool Hire: a group with a handful of depots, hire contracts, delivery and collection legs, and kit brought in from other suppliers when a depot is short (cross-hire). Every widget in this chapter runs on Marchwood, and every number in it is one you can check by hand.
The question this chapter keeps asking, from nine angles, is the same one: what could a consumer do to this model that you did not authorise — and which of those can you make impossible, rather than merely discouraged?
Three parties, one handoff: your model, the semantic layer that translates a click into SQL, and the person who never sees either. The semantic layer is not a courtesy — it is the only thing standing between what your model permits and what a stranger can accidentally ask it.
Every chapter before this one earns its keep only if the number a consumer eventually sees is the number you meant. A model that is correct and production-grade can still hand out a wrong answer through a drag-and-drop tool in under ten seconds, with a green query and no error anywhere.
- semantic layer
- The layer between a model and a BI tool that turns a drag-and-drop click into SQL — the umbrella term used throughout this chapter.
- query generator
- The part of a BI tool that compiles a report’s fields and filters into the SQL it actually runs against the warehouse.
- consumption boundary
- The point where your model stops being read by people who know its rules and starts being read by a tool that only knows its structure.
Marchwood Plant & Tool Hire — the star this chapter runs on
Grain: one row per charge line per contract.
Grain: one row per delivery or collection leg.
SCD2: an asset’s depot changes when it transfers between depots.
Treating a wrong dashboard number as a training problem for whoever built it. The same mistake reappears in the next dashboard, because nothing about the model changed — only one person’s knowledge did.
Ask, for every field a consumer can touch, what SQL dragging it could generate — not just what it means.
Treat the semantic layer as part of the model, not a presentation detail owned by someone else.
Assume the next reader has never seen your schema and never will.
A model does not answer a question. It constrains the set of SQL a tool is allowed to generate in response to one. Everything in this chapter is about narrowing that set.
"A dashboard shows the wrong number — where do you look first?" is a real interview question. A strong answer starts with the three parties, not with the SQL.
You are not just modelling data anymore — you are modelling the space of questions a tool is allowed to ask on someone else’s behalf.
