A practical guide to Looker development
A Model in Looker is the entry point for a data project. It tells Looker:
If views are tables, and explores are joinable datasets, then the model is the blueprint for how all those views and explores are wired together.
Think of the .model.lkml
file as the “routing config” for your data app.
You can have multiple .model.lkml
files in a project — each defining its own explore universe.
The model file glues together views, defines explores, sets the connection, and handles caching — it’s the brain of your Looker project.
A .model.lkml
file defines the explores available to users and sets up project-wide configs like DB connection, includes, and caching.
connection: analytics_db
include: "*.view"
include: "*.explore.lkml"
explore: orders {
from: orders
}
connection:
— Tells Looker which DB connection to use (defined in Admin panel)include:
— Brings in .view
or .explore
files from the projectexplore:
— Declares each Explore, with optional joins, filters, etc.sales.model.lkml
, marketing.model.lkml
)include:
wildcards to keep your model file clean and modularThe include:
statement lets you pull other LookML files into your model file. This is how you link your views, explores, and other config files into a model.
include: "*.view"
include: "*.explore.lkml"
include: "shared/sets/*.lkml"
*
) are allowedinclude:
is only allowed in .model.lkml
and manifest.lkml
The connection:
parameter in the model file tells Looker which database to run queries against.
Example:
connection: analytics_db
This tells Looker to use the analytics_db
connection for all explores in this model.
connection:
lineLooker uses datagroups to manage caching and refresh logic for Persistent Derived Tables (PDTs).
A datagroup
defines:
It is declared in the model file.
Example:
datagroup: hourly_refresh {
max_cache_age: "1 hour"
}
In a view with a PDT, reference the datagroup like this:
persist_with: datagroup_trigger: hourly_refresh
This tells Looker:
persist_for:
vs trigger
persist_for:
— defines static cache TTL (e.g., “24 hours”)datagroup_trigger:
— ties to a datagroup’s cache + rebuild scheduleUse datagroup_trigger
when multiple views or PDTs need to stay in sync.
Here’s a complete .model.lkml
file that includes a connection, includes, explore, and a datagroup trigger.
connection: analytics_db
include: "*.view"
include: "*.explore.lkml"
datagroup: daily_refresh {
max_cache_age: "24 hours"
}
explore: orders {
from: orders
join: users {
type: left_outer
sql_on: ${orders.user_id} = ${users.id} ;;
relationship: many_to_one
}
}
This model connects to a DB, loads all views and explores, applies a 24-hour cache policy, and defines an orders
explore with a users
join.