Editing and Validating LookML

On this Page
Docs Menu

Due to significant improvements, this page discusses the new LookML IDE and therefore shows only new LookML examples.

Using the IDE

Looker’s Integrated Development Environment (IDE) has several features to assist you in writing in LookML.

Autosuggest

As you type, the IDE suggests possible parameters and values that are context-sensitive to where you are typing. For example, when suggesting for a dimension’s type parameter, the suggestions will only include options valid for that parameter. Also, in sql parameters, fields have to be marked with ${...}, so the IDE adds that syntax when suggesting fields.

Autosuggest automatically appears wherever it can be shown. To close it, press the escape key on your keyboard. To pop it up at any point, press Ctrl+Space.

On-the-fly error checking

The IDE catches syntax errors as you type. A red X in the gutter indicates a syntax error, which is underlined in red. When you hover over the red X, a short description of the problem appears.

Note that the LookML Validator is still required to perform a full model validation. Some errors, such as an invalid field reference due to a missing join, require a holistic look at the model and therefore are only surfaced when the LookML Validator is run.

Context-sensitive help panel

On the right side of the IDE is a context-sensitive help panel that dynamically updates based on the position of your cursor. The help panel:

  • Provides a description of the LookML parameter
  • Shows all possible subparameters or a list of allowed values
  • Links to the documentation pages for the parameter and all subparameters

Automatic formatting

Select Format File from the gear menu to automatically indent your LookML file. The indentation indicates the hierarchy of parameters and subparameters, making your LookML easier to read and understand.

Folding

A small arrow appears in the gutter next to the start of each chunk of LookML. Pressing this arrow folds or unfolds that section of text so you can focus on just the section you want. The gear menu also provides Fold LookML and Unfold LookML options to fold or unfold all sections within the current file.

Marking Additions, Changes, and Deletions

The LookML IDE also has several indicators are always displayed when you are in Development Mode and have uncommitted changes:

  • A green dot next to the file name on the left side of the window indicates that the file is new or changed.
  • If you open a new or changed file, green highlighting shows the new or changed lines while a horizontal red line indicates removed lines.
  • You can see a list of deleted or renamed files at the bottom of the left side of the window.

Creating and Testing New Fields

As an example of editing LookML, we’ll add several fields and then test them.

Creating a Dimension

First we will add a new dimension to our users view that determines if a user is from either California or New York. The dimension will be type: yesno, which means it will return Yes if the user is from California or New York, and No if not.

The LookML for our new dimension looks like:

- dimension: from_ca_or_ny type: yesno sql: ${TABLE}.state = "California" OR ${TABLE}.state = "New York"
dimension: from_ca_or_ny { type: yesno sql: ${TABLE}.state = "California" OR ${TABLE}.state = "New York" ;; }

Add this dimension to the view file for the users view. Click Save to save your changes.

Check out substitution operators to learn more about ${TABLE}.state.

Creating a Measure

Next we will add a new measure to our user view that averages the age of our users. This measure will be type: average and aggregate over the column age.

The LookML for this new measure looks like:

- measure: average_age type: average sql: ${TABLE}.age
measure: average_age { type: average sql: ${TABLE}.age ;; }

Add this measure to the view file for the user view. Click Save to save your changes.

Testing the Fields in Explore

We can now test our new dimension and measure by querying them. After saving your changes, these fields will appear in the Field Picker in Explore. An easy way to access the Explore for the current view is to use the dropdown menu next to the view file name:

Once we are in the users Explore, we can select the new fields to add them to a query. A query with both the new fields shows the average age of users who are from California or New York, versus users who are not:

Note: you must be in development mode to access these new fields until you have commited and pushed your changes to production.

Validating Your Changes

When you are satisfied with your changes, you can save your changes. The IDE will alert you to any unresolved syntax errors within a single file.

Next, use the LookML Validator to perform a full model validation. Some errors, such as an invalid field reference due to a missing join, require a holistic look at the model and therefore are only surfaced when the LookML Validator is run. Be sure to validate your LookML changes before publishing them the production environment. Although validation will not catch every issue, such as database permission issues, it will prevent most errors.

The LookML Validator should not be confused with the Content Validator, which instead checks to see if the changes you’ve made will break any saved Looks.

Validating Only Updated LookML

If you want to speed up your LookML validation, you can enable the Don’t Revalidate Unchanged LookML feature in Looker Labs. When this feature is enabled, the LookML Validator will only scan the LookML files that have been updated since the last LookML validation, or files that are affected by updates:

  • If a model-level setting changes, everything is revalidated
  • If a view changes, only the Explores where it is used are revalidated
  • If an Explore changes, only that Explore is revalidated

Running Validation

To run the LookML Validator, click the Validate LookML button above the file list in the Looker IDE:

This will display a list of errors and other warnings that you should address:

The validator button will become available again if you make and save another change or fix:

Validation Messages

No LookML Issues

When there are no issues found by the validator, you will receive the No LookML Issues message in green.

LookML Errors

LookML errors are issues that could prevent queries from running. The number in parenthesis is the number of errors found (one error below):

Within the expanded list of issues you will see the reason why validation didn’t pass. Often times, if you click on the error, it will bring you directly to the problem row of code. You’ll see a red “X” next to the row. Hovering over it will provide more detailed error information in some cases:

Chat Team Tip: The validation error we are asked about most is “Unknown or inaccessible field.” Check out this article for the causes and what to do about it.

LookML Warnings

LookML warnings may not necessarily prevent a query from being run, but may still result in broken or unintended functionality for your users. As with errors, the number in parenthesis is the number of warnings found (34 warnings below):

As with LookML errors you can expand any warnings, jump to the problem code by clicking on them (in many cases), and hover over the exclamation point icon for more information:

LookML Deprecation Warnings

LookML deprecation warnings alert you to the fact that you’re using LookML parameters that have been phased out in favor of others. While your project will still function for the time being, eventually these parameters will be turned eliminated, which will result in future problems. It’s best to update parameters as you go to avoid creating an urgent, large amount of work when they are eliminated.

As with errors and warnings, you can expand deprecation warnings and jump to problem code by clicking on them (in many cases).

Deploying Your Changes

After you’ve validated that your changes will work properly, you can use Looker’s Git integration to commit and deploy your changes to production.

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