# Use the LookML Library

The LookML Library for MDE provides
abstract core files, and packaged views, explores and dashboards to help you get
started with building your own LookML models on top of the
MDE data in BigQuery.

## Before you begin

To complete this guide, you need the following prerequisites:

- You configured a new Looker project using the *MDE Project Template* as described in the [setup guide](https://docs.cloud.google.com/manufacturing-data-engine/docs/guides/analyze/how-to-set-up-a-new-mde-Looker-project).
- You have an active MDE deployment.
- **Optional** . You applied the default [MDE configuration package](https://docs.cloud.google.com/manufacturing-data-engine/docs/deployment/guide#apply-the-default-configuration-packages). While you can use the *MDE LookML Library* to create custom views, the *default* LookML package requires the *default* MDE configuration package is applied.

## Exploring library contents

After the project is allowed, you can explore the contents of the library
under the `imported_projects/mde_lookml_lib` directory in the
Looker development console. The library provides content in
two directories:

- `mde_abstract_core`
- `mde_packages`

### Abstract core directory

The `mde_abstract_core` directory provides base views that you can use to
model MDE metadata buckets as dimensions and
MDE record tables as fact tables in Looker.
The base views save you from needing define the shared fields across
these views.

The library provides a `dim_base.view` view for building dimensions, which
you can find in
`imported_projects/mde_lookml_lib/mde_abstract_core/views/dimension/dim_base.view.lkml`.
The following example shows how you can extend the base view to define a
dimension called `device`:

```yaml

include: "//mde_lookml_lib/mde_abstract_core/views/dimension/*.view"

view: dim_source {

   derived_table: {
      sql: SELECT * FROM `mde_dimension.metadata-store` where bucket_number = BUCKET_NUMBER ;;
   }

   view_label: "DIM - Device"
   extends: [ dim_base ]

   dimension: device_name {
      type: string
      sql: JSON_VALUE(${TABLE}.instance,"$.device_name") ;;
   }

}
```

And, similarly, the library provides base views per MDE
archetype for modeling record tables in BigQuery as fact
tables. You can find the base views under
`imported_projects/mde_lookml_lib/mde_abstract_core/views/fact/`. You can
extend the archetype base views to define custom fact views in
Looker. The following example shows how you can define a fact
view called `sensor_readings`:

```yaml

include: "//mde_lookml_lib/mde_abstract_core/views/fact/fct_numeric_archetype.view"

view: fct_sensor_readings {
   extends: [ fct_numeric_archetype ]
   label: "FCT - Sensor Readings"
   sql_table_name: `mde_data.sensor-readings` ;;
}

```

### Packages

The `mde_packages` directory contains prebuilt LookML packages for
MDE. These packages provide use-case specific explores,
views and dashboards to get you started quickly.

The *default* Looker configuration package works in conjunction
with the *default* MDE configuration package. For more
information, see the [Default configuration package guide](https://docs.cloud.google.com/manufacturing-data-engine/docs/resources/default-configuration-package).
The default Looker configuration package provides a fact table
per record table linked to an MDE type, as well tag and
source dimensions, which correspond to the tag and source metadata buckets in
MDE, respectively.

If you used the MDE Project Template to
[bootstrap](https://docs.cloud.google.com/manufacturing-data-engine/docs/guides/analyze/how-to-set-up-a-new-mde-looker-project.md.txt)
a new MDE project, the provided Looker model
automatically imports the views and explores from the default package:

```yaml
connection: "@{looker_connection}"

########## DEFAULT MDE EXPLORES ##########
include: "//mde_lookml_lib/mde_packages/default/explores/default.explore.lkml"

############ CUSTOM VIEWS ################
include: "/views/dimension/*.view"
include: "/views/fact/*.view"
```

Once your project is set up, you can use the default default explores in
Looker to analyze data.

You can also use other configuration packages included in the
library. See the following section for further instructions and
prerequisites to use these packages in the library.

## Extend views provided by the configuration packages in the library

You can extend the fact and dimension views included in the library by using the
[extends](https://docs.cloud.google.com/looker/docs/reusing-code-with-extends.md.txt#:%7E:text=To%20extend%20a%20LookML%20object,versions%20of%20the%20LookML%20object.)
syntax. For example, in your project model file you can extend the `dim_tag` by
defining additional dimension fields on the deviceMetadata object, as the
following script shows:

```yaml
view: +dim_tag {
dimension: device_type {
type: string
sql: JSON_VALUE(${TABLE}.instance,"$.deviceMetadata.deviceType") ;;
}
dimension: location {
type: string
sql: JSON_VALUE(${TABLE}.instance,"$.deviceMetadata.location") ;;
}
}
```

## Dashboards access is defined in the *default* configuration package

The LookML model defined in the *MDE Project Template*
imports all the dashboards from the default package in
*MDE LookML Library*. To access any of
these dashboards, open the following link:

`https://LOOK_HOST/dashboards/mde::DASHBOARD_ID`

Replace the following:

- `LOOK_HOST` with the hostname of your Looker instance.
- `DASHBOARD_ID` with the ID of the dashboard you want to open. You can look up the dashboard ID, by opening the relevant .dashboard file in the `imported_projects/mde_lookml_lib/mde_packages/default/dashboards/` directory and copying the value of the `dashboard` property.