Release 3.24 will come with the ability to extend Explores and Views. These are key features in building reusable models.
Building extensions is a pretty advanced topic. In order to understand how this works, you will first need to understand LookML’s facilities for naming explores, views and fields. Take a moment to review this, even if you are familiar with it. The subtleties are important.
LookML is implemented as an array of hashes in YAML. Each LookML Object (explore, view, field, join, dashboard, or dashboard element) is a named hash. LookML’s extensions are a mechanism for deeply copying and merging these objects.
Extending Explores and Views in an Existing Model
A design goal for extensions is that you can put all your extensions into a new separate file so that if the original model changes, you get all of the changes. Additionally, all the logic surrounding the extension is on one place. For example, a rolling average extension includes the explore, view and field definitions as well as dashboard that displays rolling averages. Simply drop the file into your model and change the name of the explore being extended.
Example
Assume the base e-commerce model:
Notice that the view: parameter is set in the explore. The view to use in an explore is by default the same name as the explore. Setting the view: allows the explore to be extended without having to set this parameter (this will likely be automatically set by the generator in the future).
- explore: orders
view: orders
joins:
- join: users
foreign_key: orders.user_id
- join: order_items
sql_on: ${order_items.order_id} = ${orders.id}
relationship: one_to_many
- join: inventory_items
foreign_key: order_items.inventory_item_id
- join: products
foreign_key: inventory_items.product_id
Extending a joined view within an Explore.
Suppose the original model doesn’t have much in the way of age analysis. We can extend the model by simply creating a file with our extensions.
Extending a view within an explore happens in two steps:
- Create a new view that has the desired fields to extend the original view. In this case, we extend users.
- Create a new explore that extends orders, change the view for users by declaring the
from:
parameter. Notice that the linkage for users was copied from the join in the original orders view.
- explore: orders_with_age_extensions
extends: orders
joins:
- join: users
from: users_with_age_extensions
- view: users_with_age_extensions
extends: users
fields:
- measure: average_age
type: average
sql: ${age}
- dimension: age_tiers
type: tier
style: integer
tiers: [10,20,30,50,70]
sql: ${age}
sets:
detail: [SUPER*, age]
Example Extending just the Base View
There are 4 names associated with an explore. Its name in the UI (label:), its name in the url (explore:), the view that it is built from (from:), and the alias to use in the sql query and to prefix fields with (view:). It is important to understand each of these use cases. When extending a view, you usually want to change most of these.
- explore: better_orders
extends: orders
view: orders
from: orders_extended
- view: orders_extended
extends: orders
fields:
- measure: count_in_california
type: count
filters:
users.state: California
Play with it.
There is additional information about how this will work on learnbeta. Chat with a looker support analyst if you would like to play and don’t have an account.
Comment on it.
We’d love to hear your feedback. Let us know how you’re using the feature, what else you’d like to do with it, or anything else you think we should know.