Understanding Model and View Files

LookML
Version

On this Page
Docs Menu

This page discusses accessing project files and provides an overview of the basic components of a data model in LookML. You'll learn the structure of your model and view files, giving you a foundation for designing and developing your own customizations.

Accessing Project Files

You can access project files by going to the Develop navigation menu and selecting the project you would like to view. This will take you to the LookML file browser page. The file browser in Looker groups files by type: Documentation, Model, View, Dashboard, or Data.

Note: You must be in development mode in order to edit files.

  1. Click Develop.
  2. Click the project you want to examine.
  3. Click the file you want to examine. Files with changes are marked with a green dot.
  4. View the code in that file. Lines with changes are highlighted on the edge in green.
  5. Expand the right sidebar to see explanations and options for the current location in the code. You can also click a parameter name in the sidebar to go to Looker documentation for that parameter.

You can also directly access the LookML for a field from Explore. This can be done in several ways:

  • Click the Looker icon that appears to the left of the field name:

  • Click Go to LookML from the gear drop down menu for a field:

After selecting a field, you will be taken directly to the field definition in the corresponding view file.

Model Files

Model files define explores and their relationships to other views.

An "explore" is a starting place for querying your data. In SQL terms, an explore is the FROM clause of a query. Explores defined in the model file appear in the explore menu in Looker.

Structure and General Syntax

Within an explore's curly braces, { }, you define parameters for the explore. You can use join parameters to join other views to an explore in a model file.

Above we see the order_items explore in the model file, along with its joined views. This LookML definition causes "Order Items" to appear in the Explore menu, and joins data from order_items to inventory_items and user.

Creating Model Files

Most LookML developers start with one or more model files created by generating from a set of tables in a database.

Alternatively, a blank model file can be created in Development Mode:

  1. Click + next to Add Files.
  2. Click Create Model.
  3. Name the model file and press return.

You can also drag a file with the extension .model.lkml into the LookML IDE, which adds the file into the Models section.

You can modify any model file by adding or removing explores, specifying joins, and adding other functionality.

Learning More About Parameters in Model Files

Read the Model Reference, Explore Reference and Join Reference to learn more about LookML parameters in the model file.

View Files

A view file generally defines a single "view" within Looker. A view corresponds to either a single table in your database or a single derived table.

Structure and General Syntax

Within each view's curly braces, { }, are field definitions, which usually correspond to a column in the underlying table or a calculation in Looker. Looker categorizes most of them as either dimensions or measures.

Above we see the dimension id defined as a field in the Order Items view. This definition exposes the "ORDER ITEMS Id" field for queries in the Order Items explore.

You can also create several time-based dimensions at once using dimension groups or specify a filter for your users with filter fields. Check out the View Reference to learn more about LookML parameters in view files.

Dimensions

Fields in Looker are split into dimensions and measures. A "dimension" can be one of two things:

  • A column in your underlying table

- dimension: first_name sql: ${TABLE}.first_name
dimension: first_name { sql: ${TABLE}.first_name ;; }

  • A computed value based on other fields

- dimension: full_name sql: CONCAT(${first_name}, ' ', ${last_name})
dimension: full_name { sql: CONCAT(${first_name}, ' ', ${last_name}) ;; }

In Looker, dimensions always appear in the GROUP BY clause of the SQL that Looker generates.

In LookML, you can define different dimension types that correspond to different data types or formatting.

Measures

A measure computes values across multiple rows. This is equivalent to SQL aggregate functions like COUNT(), SUM(), AVG(), MIN() and MAX(). Measures can also perform simple transformations on other measures. Check out our measure types documentation to learn more.

Above we can see dimensions and measures defined in the products view file.

Creating View Files

Most LookML developers start with one or more view files created by generating from a set of tables in a database.

Alternatively, a new view file can be created:

  • By creating a view from an existing database table
  • By using a query in SQL Runner to generate a view based on a derived table
  • By creating a blank view file and manually creating the view

This article describes how to create view files using these alternative techniques.

You can also drag a file with the extension .view.lkml into the LookML IDE, which adds the file into the Models section.

Learning More About Parameters in View Files

You can learn more about view parameters in the View Parameters Reference.

Read more about LookML parameters for dimensions, measures, dimension groups, and filter fields in the Field Parameters Reference.

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