This page provides an overview of model and view files, which are key components of most Looker projects. The other types of project files are described on the Understanding other project files documentation page. For information on accessing a project’s files, see the Accessing and editing project information documentation page.
Model files
A model file specifies a database connection and the set of Explores that use that connection. A model file also defines the Explores themselves 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. The Explores you define in the model are seen by your users when they look at Looker’s Explore menu. (See the How a project works in Looker documentation page for more information on Explores.)
In other words, the model file is where you define which data tables should be used (as included views) and how they should be joined together, if necessary.
Explores are usually defined within a model file. However, sometimes you need a separate Explore file for a derived table, or to extend or refine an Explore across models.
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 explore
called inventory_items
in the model file, along with its joined views. This LookML definition causes Inventory Items to appear in the Explore menu, and joins data from inventory_items
to products
and distribution_centers
.
For more specific information on the LookML structures in a model file, see the LookML terms and concepts documentation page.
Creating model files
Most LookML developers start with one or more model files that are created automatically when the LookML project is generated from a set of tables in a database.
Alternatively, a Looker developer in Development Mode can create a blank model file in the following ways:
- Using the Create Model File option to create the file using the Looker IDE (see the Creating files section on the Working with folders in the IDE documentation page for the procedure).
- Using the drag-and-drop feature to upload the file from your computer (see the Uploading files section on the Working with folders in the IDE documentation page for the procedure). Be sure to use the file extension
.model.lkml
for the file you’re uploading.
You can modify any model file by adding or removing Explores, specifying joins, and adding other functionality.
If you need to rename a model or any object in the model, do not rename the file or the object itself. Instead, use the
label
oralias
parameter to change the displayed name of the file or object. Thelabel
andalias
parameters change the displayed name while preserving the underlying URL used for emails or other systems.In general, you should take precautions to make model changes as noninvasive as possible. If you do need to rename a model or an object, use the Content Validator to update all references to the model or object.
If you delete a model file, the model is not removed from any model sets to which the model belonged. If a new model file is created with the same name as a deleted model, the new model is included in any model sets that included the deleted model. This can result in giving unwanted access to the new model file. Looker admins can edit model sets and remove a deleted model to prevent this issue.
Learning more about parameters in model files
Read the Model parameters, Explore parameters, and Join parameters documentation pages 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.
The view file specifies a table to query and the fields (dimensions and measures) to include from that 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 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 parameters documentation page to learn more about LookML parameters in view files.
For more specific information on the LookML structures in a view file, see the LookML terms and concepts documentation page.
Dimensions
Fields in Looker are split into dimensions and measures. A dimension can be one of two things:
- A column in your underlying table
- A computed value based on other fields
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 that are created automatically when the LookML project is generated from a set of tables in a database. However, there are many ways a Looker developer in Development Mode can add view files to a LookML project:
Creating view files based on tables in a database:
- Generating view files from database tables when you first connect to your database, as described on the Generating a model documentation page.
- Generating view files from database tables for a project that is already connected to a database, as described in the Adding a new view from an existing database table section below on this page.
Creating blank view files:
- Using the Create View File option in the Looker IDE, as described in the Creating files section on the Working with folders in the IDE documentation page.
- Using the drag-and-drop feature to upload the file from your computer, as described in the Uploading files section on the Working with folders in the IDE documentation page. Be sure to use the file extension
.view.lkml
for the file you’re uploading.
Creating a view file for a derived table:
- Starting with a blank view file using one of the options above, then manually defining your derived table, as described in the Defining a native derived table in LookML section of the Creating native derived tables documentation page.
- Having Looker create the derived table LookML from an Explore, as described in the Using an Explore to begin defining your native derived tables section of the Creating native derived tables documentation page.
- Having Looker create the derived table LookML from a SQL Runner query, as described on the Using SQL Runner to create derived tables documentation page.
To use a new view, add it to your model file using the explore
parameter, or use the join
parameter to join it to an existing Explore in your model file.
Adding a new view from an existing database table
You can create a view file from an existing database table while in Development Mode.
Within a project, click + at the top of the project file list in the Looker IDE, or you can click a folder’s menu to create the file inside the folder.
Click Create View From Table.
Looker displays a list of tables associated with one of your connections. To change the connection, use the Connection drop-down in the upper left.
Select any tables that you would like to create views from by checking the box to the left of the table name. You can collapse and expand databases or schemas in this list to access all available tables.
Scroll to the bottom of the page and click Create Views.
Looker generates views containing LookML for all the table columns.
Learning more about parameters in view files
You can learn more about view parameters on the View parameters documentation page.
Read more about LookML parameters for dimensions, measures, dimension groups, and filter fields on the Field parameters documentation page.