# Analytics views

Manufacturing Data Engine (MDE) Analytics views is a powerful feature
designed to streamline data analysis and reporting within your
MDE environment. By automatically
generating BigQuery views that consolidate type-specific data, metadata,
and associated dimensions, MDE simplifies
the creation of comprehensive queries and dashboards.

## Concepts

An Analytics view is a prebuilt BigQuery view tailored to a
specific type version within your MDE environment. This
view acts as a unified data source, seamlessly joining the type table
(your core fact table) with all relevant metadata buckets (your dimensions)
associated with that type version.

This consolidation simplifies querying by eliminating the need for manual joins
across multiple tables. Analytics views also flatten metadata instances and data
fields based on predefined JSON schemas.

## How Analytics views work

1. **Automatic creation:** MDE automatically creates a
   dedicated Analytics view within the `mde_analytics` dataset for each unique
   type version. Views for new type versions are always updated in-place.

2. **Metadata flattening:** The view query intelligently flattens the JSON
   metadata instances (dimension members) associated with the type. Each field
   within the JSON schema of the metadata bucket version associated with the
   type version is mapped to a corresponding BigQuery field,
   adhering to the following well-defined type mapping:

   - String -\> String
   - Array -\> JSON
   - Object -\> JSON
   - Number -\> Float64
   - Integer -\> Int64
   - Boolean -\> Bool
   - null -\> null

The resulting BigQuery fields are always prefixed with the
metadata bucket name.

1. **Nested JSON Handling:** Nested JSON fields are converted into
   BigQuery fields by concatenating their path elements with
   underscores. For example, `{"location":{"city":"Düsseldorf"}}` becomes
   `location_city`.

2. **"Data" Field Flattening:** The view extends flattening to the JSON "data"
   field for non-numeric types based on the schema defined for the type,
   ensuring comprehensive data accessibility. Flattening is performed only when
   a schema for the "data" field is defined. For more details about data field
   schemas, see [data field](https://docs.cloud.google.com/manufacturing-data-engine/docs/concepts/type.md.txt#data_field).

3. **Field Naming and Conflicts:** In case of a naming conflict, fields derived
   from metadata buckets are prefixed with the bucket name.

## View Schema

The final view schema encompasses a rich set of fields:

- **All fields from the underlying type table:** Your core manufacturing data.
- **All flattened fields from each metadata instance:** Detailed contextual information about your records.
- **All flattened fields from the "data" field (non-numeric):** Additional data points specific to the type.

## Benefits of Analytics views

The following are the benefits of Analytics views:

- **Simplified Querying:** Eliminate complex joins by querying a single view for comprehensive data.
- **Accelerated Analysis:** Spend less time on data preparation and more time on extracting insights.
- **Standardized Structure:** Consistent schema across type versions facilitates standardized reporting.
- **Automation:** MDE handles view creation and maintenance, avoiding you from manual tasks.

## Getting started

Analytics views are ready to use as soon as you start working with types in
MDE. You can explore the automatically
generated views in your Google Cloud project with the following steps:

1. Select BigQuery.
2. Click **Studio** on the left panel.
3. Select the `mde_analytics` dataset on the BigQuery explorer window.