Extending Explores to a Different Model


(Segah Mir@Caura & Co.) #1

A common problem that organizations have is providing all of the necessary data without drowning the user in irrelevant data. For example, consider the following situation:

The marketing team and finance team share a lot of the same data. However, the marketing team has lots of data that is irrelevant to the finance team. The finance team should be able to choose to view only the data relevant to them, without being overwhelmed with marketing-specific content.

LookML extends allows precisely this functionality.

Take these two models as an example:

  • finance
  • marketing

Our finance model might look as follows:

Old LookML
- connection: default_name

- include: "*.view.lookml"
- include: "*.dashboard.lookml"

# this explore will not be accessible - it is just a template
- explore: order_items
  view: order_items
  from: order_items
  extension: required
  joins:
    - join: orders
      type: left_outer 
      sql_on: ${order_items.order_id} = ${orders.id}
      relationship: many_to_one


- explore: order_items_finance
  extends: order_items
New LookML
connection: "default_name"

include: "*.view.lkml"
include: "*.dashboard.lkml"

# this explore will not be accessible - it is just a template
explore: order_items {
  view_name: order_items
  from: order_items
  extension: required

  join: orders {
    type: left_outer
    sql_on: ${order_items.order_id} = ${orders.id} ;;
    relationship: many_to_one
  }
}

explore: order_items_finance {
  extends: [order_items]
}

While this is enough for the finance model, marketing actually needs more user-specific information to identify cohorts by referral source and age demographics.

For that we can extend the finance model:

Old LookML
- connection: default_name

- include: "finance.model.lookml"

- explore: order_items_marketing
  extends: order_items
  joins:
    - join: users
      type: left_outer 
      sql_on: ${orders.user_id} = ${users.id}
      relationship: many_to_one

New LookML
connection: "default_name"

include: "finance.model.lkml"

explore: order_items_marketing {
  extends: [order_items]

  join: users {
    type: left_outer
    sql_on: ${orders.user_id} = ${users.id} ;;
    relationship: many_to_one
  }
}

With this, there should only now be one explore showing under two models (finance & marketing). Also, the finance model will exclude marketing fields.

Notes:

  • by repeating the connection name, we are overwriting the one previously specified.
  • in the marketing file, avoid using include: "*.view.lookml" (or include: "*.view.lkml" in New LookML) - this can lead to certain files be included multiple times.

(andy) #2

For each old LookML code block in this article and its comments, we just added the New LookML equivalent code.


(Camille Vernon | Data Operations Analyst) #3

Just a note that the option to minimize the Old LookML code sections does not seem to be working. Thank you for adding the New LookML code sections to this article!


(Paul Stubley) #4

Also the New Lookml code isn’t formatted very well for the last block.


(Seth Newman) #5

Is it possible to extend an explore from a source model without including the other explores from that model?


(Chris Seymour) #6

Hey @Seth_Newman,

Currently including a file is all-or-nothing, so if you have a single explore that you’d like to use across different models, I would recommend putting that explore into a separate base.lkml file that you can then include in any model that you want to use those explores. You can see more details on how to do this in Lloyd’s comment here: Extending Model to Include Sensitive Information