What is LookML?

LookML
Version

On this Page
Docs Menu

LookML is a language for describing dimensions, aggregates, calculations and data relationships in a SQL database. The Looker app uses a model written in LookML to construct SQL queries against a particular database.

LookML Projects

A LookML Project is a collection of model, view, and dashboard files that are typically version controlled together via a git repository. The model files contain information about which tables to use, and how they should be joined together. The view files contain information about how to calculate information about each table (or across multiple tables if the joins permit them).

LookML separates structure from content, so the query structure (how tables are joined) is independent of the query content (the columns to access, derived fields, aggregate functions to compute, and filtering expressions to apply).

LookML separates content of queries from structure of queries

SQL Queries Generated by Looker

For data analysts, LookML fosters DRY style (“don’t repeat yourself”), meaning you write SQL expressions once, in one place, and Looker uses the code repeatedly to generate ad-hoc SQL queries on the fly. For business users, the end result is the ability to build complex queries in Looker, focusing only on the content they need, not the complexities of SQL structure.

A query built in Looker that joins values from multiple tables (ORDERS and USERS)

In the figure above, the end-user doesn’t need to understand SQL expressions for joins or filtering.

A Dependency Language for Describing Data Structures

LookML is a dependency language like make, as opposed to an imperative language like C or Ruby. LookML provides predefined data types and syntax for data modeling. LookML syntax is YAML-based, so the structure is clear and easy to learn. (You don’t need prior experience with YAML or other programming languages. Everything you need to know is documented here.) LookML is independent of particular SQL dialects, and encapsulates SQL expressions to support any SQL implementation.

Code Sample

Below is an example of a minimal yet complete model, included here to give you a sense of what LookML looks like. Don’t worry about the details for now, but just get a high-level sense of the code.

In old LookML, scoping is controlled by indentation. Note the following keywords, which you’ll learn about in the later lessons: explore, joins, view, dimension, measure, type, and sets.

An example model in LookML: E-commerce store

###################################### # FILE: ecommercestore.model.lookml # # Define the explores and join logic # ###################################### - connection: order_database - include: "*.view.lookml" # include all the views   - explore: orders joins: - join: customers sql_on: ${orders.customer_id} = ${customers.id}   ########################################################## # FILE: orders.view.lookml # # Define the dimensions and measures for the ORDERS view # ########################################################## - view: orders fields: - dimension: id primary_key: true type: number sql: ${TABLE}.id   - dimension: customer_id # field: orders.customer_id sql: ${TABLE}.customer_id   - dimension: amount # field: orders.amount type: number value_format: '0.00' sql: ${TABLE}.amount   - dimension_group: created # generates fields: type: time # orders.created_time, orders.created_date timeframes: [time, date, week, month] # orders.created_week, orders.created_month sql: ${TABLE}.created_at   - measure: count # field: orders.count type: count # creates a sql COUNT(*) drill_fields: drill_set # list of fields to show when someone clicks 'ORDERS Count'   - measure: total_amount # field: orders.total_amount type: sum sql: ${amount} # SUM(orders.amount)   sets: drill_set: # set: orders.drill_set - id # list of fields to show when someone clicks 'ORDERS Count' - created_time - customers.name - amount   ############################################################# # FILE: customers.view.lookml # # Define the dimensions and measures for the CUSTOMERS view # ############################################################# - view: customers fields: - dimension: id primary_key: true type: number sql: ${TABLE}.id   - dimension: city # field: customers.city sql: ${TABLE}.city   - dimension: state # field: customers.state sql: ${TABLE}.state   - dimension: name sql: CONCAT(${TABLE}.firstname, " ", ${TABLE}.lastname)   - measure: count # field: customers.count type: count # creates a sql COUNT(*) drill_fields: drill_set # fields to show when someone clicks 'CUSTOMERS Count'   sets: drill_set: # set: customers.drill_set - id # list of fields to show when someone clicks 'CUSTOMERS Count' - name - state - orders.count
###################################### # FILE: ecommercestore.model.lkml # # Define the explores and join logic # ###################################### connection: order_database include: "*.view.lkml" explore: orders { join: customers { sql_on: ${orders.customer_id} = ${customers.id} ;; } }   ########################################################## # FILE: orders.view.lkml # # Define the dimensions and measures for the ORDERS view # ########################################################## view: orders { dimension: id { primary_key: yes type: number sql: ${TABLE}.id ;; } dimension: customer_id { # field: orders.customer_id sql: ${TABLE}.customer_id ;; } dimension: amount { # field: orders.amount type: number value_format: "0.00" sql: ${TABLE}.amount ;; } dimension_group: created { # generates fields: type: time # orders.created_time, orders.created_date timeframes: [time, date, week, month] # orders.created_week, orders.created_month sql: ${TABLE}.created_at ;; } measure: count { # field: orders.count type: count # creates a sql COUNT(*) drill_fields: [drill_set] # list of fields to show when someone clicks 'ORDERS Count' } measure: total_amount { type: sum sql: ${amount} ;; } set: drill_set { fields: [id, created_time, customers.name, amount] } }   ############################################################# # FILE: customers.view.lkml # # Define the dimensions and measures for the CUSTOMERS view # ############################################################# view: customers { dimension: id { primary_key: yes type: number sql: ${TABLE}.id ;; } dimension: city { # field: customers.city sql: ${TABLE}.city ;; } dimension: state { # field: customers.state sql: ${TABLE}.state ;; } dimension: name { sql: CONCAT(${TABLE}.firstname, " ", ${TABLE}.lastname) ;; } measure: count { # field: customers.count type: count # creates a sql COUNT(*) drill_fields: [drill_set] # fields to show when someone clicks 'CUSTOMERS Count' } set: drill_set { # set: customers.drill_set fields: [id, state, orders.count] # list of fields to show when someone clicks 'CUSTOMERS Count' } }

Overview of Fundamental LookML Elements

The following diagram shows fundamental LookML elements and their relationships. For more detail, see LookML Terms and Concepts.

Still have questions?
Go to Discourse - or - Email Support
Top