Skip to content

Commit

Permalink
update meta
Browse files Browse the repository at this point in the history
  • Loading branch information
mirnawong1 committed Nov 18, 2024
1 parent 2d5a675 commit c34e68e
Show file tree
Hide file tree
Showing 7 changed files with 416 additions and 51 deletions.
12 changes: 6 additions & 6 deletions website/docs/docs/build/conversion-metrics.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@ Note that we use the double colon (::) to indicate whether a parameter is nested
| `entity` | The entity for each conversion event. | Required |
| `calculation` | Method of calculation. Either `conversion_rate` or `conversions`. Defaults to `conversion_rate`. | Optional |
| `base_measure` | A list of base measure inputs | Required |
| `base_measure:name` | The base conversion event measure. | Required |
| `base_measure:fill_nulls_with` | Set the value in your metric definition instead of null (such as zero). | Optional |
| `base_measure:join_to_timespine` | Boolean that indicates if the aggregated measure should be joined to the time spine table to fill in missing dates. Default `false`. | Optional |
| `base_measure::name` | The base conversion event measure. | Required |
| `base_measure::fill_nulls_with` | Set the value in your metric definition instead of null (such as zero). | Optional |
| `base_measure::join_to_timespine` | Boolean that indicates if the aggregated measure should be joined to the time spine table to fill in missing dates. Default `false`. | Optional |
| `conversion_measure` | A list of conversion measure inputs. | Required |
| `conversion_measure:name` | The base conversion event measure.| Required |
| `conversion_measure:fill_nulls_with` | Set the value in your metric definition instead of null (such as zero). | Optional |
| `conversion_measure:join_to_timespine` | Boolean that indicates if the aggregated measure should be joined to the time spine table to fill in missing dates. Default `false`. | Optional |
| `conversion_measure::name` | The base conversion event measure.| Required |
| `conversion_measure::fill_nulls_with` | Set the value in your metric definition instead of null (such as zero). | Optional |
| `conversion_measure::join_to_timespine` | Boolean that indicates if the aggregated measure should be joined to the time spine table to fill in missing dates. Default `false`. | Optional |
| `window` | The time window for the conversion event, such as 7 days, 1 week, 3 months. Defaults to infinity. | Optional |
| `constant_properties` | List of constant properties. | Optional |
| `base_property` | The property from the base semantic model that you want to hold constant. | Optional |
Expand Down
107 changes: 106 additions & 1 deletion website/docs/docs/build/dimensions.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,26 @@ Groups are defined within semantic models, alongside entities and measures, and

All dimensions require a `name`, `type`, and can optionally include an `expr` parameter. The `name` for your Dimension must be unique within the same semantic model.

:::tip
Note that we use the double colon (::) to indicate whether a parameter is nested within another parameter. So for example,` config::config_name` means the `config_name` parameter is nested under `config`.
:::

<VersionBlock lastVersion="1.8">

| Parameter | Description | Type |
| --------- | ----------- | ---- |
| `name` | Refers to the name of the group that will be visible to the user in downstream tools. It can also serve as an alias if the column name or SQL query reference is different and provided in the `expr` parameter. <br /><br /> Dimension names should be unique within a semantic model, but they can be non-unique across different models as MetricFlow uses [joins](/docs/build/join-logic) to identify the right dimension. | Required |
| `type` | Specifies the type of group created in the semantic model. There are two types:<br /><br />- **Categorical**: Describe attributes or features like geography or sales region. <br />- **Time**: Time-based dimensions like timestamps or dates. | Required |
| `type_params` | Specific type params such as if the time is primary or used as a partition | Required |
| `description` | A clear description of the dimension | Optional |
| `expr` | Defines the underlying column or SQL query for a dimension. If no `expr` is specified, MetricFlow will use the column with the same name as the group. You can use the column name itself to input a SQL expression. | Optional |
| `label` | A recommended string that defines the display value in downstream tools. Accepts plain text, spaces, and quotes (such as `orders_total` or `"orders_total"`). | Optional |
| `config` | Use the [`config`](/reference/resource-properties/config) property to specify configurations for your metric. Supports [`meta`](/reference/resource-configs/meta), [`group`](/reference/resource-configs/group), and [`enabled`](/reference/resource-configs/enabled) configs. | Optional |

</VersionBlock>

<VersionBlock firstVersion="1.9">

| Parameter | Description | Type |
| --------- | ----------- | ---- |
| `name` | Refers to the name of the group that will be visible to the user in downstream tools. It can also serve as an alias if the column name or SQL query reference is different and provided in the `expr` parameter. <br /><br /> Dimension names should be unique within a semantic model, but they can be non-unique across different models as MetricFlow uses [joins](/docs/build/join-logic) to identify the right dimension. | Required |
Expand All @@ -22,7 +42,10 @@ All dimensions require a `name`, `type`, and can optionally include an `expr` pa
| `description` | A clear description of the dimension | Optional |
| `expr` | Defines the underlying column or SQL query for a dimension. If no `expr` is specified, MetricFlow will use the column with the same name as the group. You can use the column name itself to input a SQL expression. | Optional |
| `label` | A recommended string that defines the display value in downstream tools. Accepts plain text, spaces, and quotes (such as `orders_total` or `"orders_total"`). | Optional |
| `meta` | Use the [`meta` field](/reference/resource-configs/meta) to set metadata for a resource and organize resources. Accepts plain text, spaces, and quotes (such as `orders_total` or `"orders_total"`). | Optional |
| `config` | Use the [`config`](/reference/resource-properties/config) property to specify configurations for your metric. Supports [`meta`](/reference/resource-configs/meta), [`group`](/reference/resource-configs/group), and [`enabled`](/reference/resource-configs/enabled) configs. | Optional |
| `config::meta` | Use [`meta`](/reference/resource-configs/meta), nested under `config`, to set metadata for a resource and organize resources. Accepts plain text, spaces, and quotes (such as `orders_total` or `"orders_total"`). | Optional |

</VersionBlock>

Refer to the following for the complete specification for dimensions:

Expand All @@ -38,6 +61,8 @@ dimensions:
Refer to the following example to see how dimensions are used in a semantic model:
<VersionBlock firstVersion="1.9">
```yaml
semantic_models:
- name: transactions
Expand Down Expand Up @@ -69,6 +94,40 @@ semantic_models:
- name: type
type: categorical
```
</VersionBlock>
<VersionBlock lastVersion="1.8">
```yaml
semantic_models:
- name: transactions
description: A record for every transaction that takes place. Carts are considered multiple transactions for each SKU.
model: {{ ref('fact_transactions') }}
defaults:
agg_time_dimension: order_date
# --- entities ---
entities:
- name: transaction
type: primary
...
# --- measures ---
measures:
...
# --- dimensions ---
dimensions:
- name: order_date
type: time
type_params:
time_granularity: day
label: "Date of transaction" # Recommend adding a label to provide more context to users consuming the data
expr: ts
- name: is_bulk
type: categorical
expr: case when quantity > 10 then true else false end
- name: type
type: categorical
```
</VersionBlock>
Dimensions are bound to the primary entity of the semantic model they are defined in. For example the dimension `type` is defined in a model that has `transaction` as a primary entity. `type` is scoped to the `transaction` entity, and to reference this dimension you would use the fully qualified dimension name i.e `transaction__type`.

Expand Down Expand Up @@ -104,6 +163,8 @@ This section further explains the dimension definitions, along with examples. Di

Categorical dimensions are used to group metrics by different attributes, features, or characteristics such as product type. They can refer to existing columns in your dbt model or be calculated using a SQL expression with the `expr` parameter. An example of a categorical dimension is `is_bulk_transaction`, which is a group created by applying a case statement to the underlying column `quantity`. This allows users to group or filter the data based on bulk transactions.

<VersionBlock firstVersion="1.9">

```yaml
dimensions:
- name: is_bulk_transaction
Expand All @@ -112,6 +173,17 @@ dimensions:
meta:
usage: "Filter to identify bulk transactions, like where quantity > 10."
```
</VersionBlock>

<VersionBlock lastVersion="1.8">

```yaml
dimensions:
- name: is_bulk_transaction
type: categorical
expr: case when quantity > 10 then true else false end
```
</VersionBlock>

## Time

Expand All @@ -135,6 +207,8 @@ You can set `is_partition` for time to define specific time spans. Additionally,

Use `is_partition: True` to show that a dimension exists over a specific time window. For example, a date-partitioned dimensional table. When you query metrics from different tables, the dbt Semantic Layer uses this parameter to ensure that the correct dimensional values are joined to measures.

<VersionBlock firstVersion="1.9">

```yaml
dimensions:
- name: created_at
Expand Down Expand Up @@ -163,6 +237,37 @@ measures:
expr: 1
agg: sum
```
</VersionBlock>

<VersionBlock lastVersion="1.8">

```yaml
dimensions:
- name: created_at
type: time
label: "Date of creation"
expr: ts_created # ts_created is the underlying column name from the table
is_partition: True
type_params:
time_granularity: day
- name: deleted_at
type: time
label: "Date of deletion"
expr: ts_deleted # ts_deleted is the underlying column name from the table
is_partition: True
type_params:
time_granularity: day
measures:
- name: users_deleted
expr: 1
agg: sum
agg_time_dimension: deleted_at
- name: users_created
expr: 1
agg: sum
```
</VersionBlock>

</TabItem>

Expand Down
69 changes: 63 additions & 6 deletions website/docs/docs/build/entities.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,17 +95,67 @@ Natural keys are columns or combinations of columns in a table that uniquely ide

The following is the complete spec for entities:

<VersionBlock firstVersion="1.9">

```yaml
semantic_models:
- name: semantic_model_name
..rest of the semantic model config
entities:
- name: entity_name ## Required
type: Primary, natural, foreign, or unique ## Required
description: A description of the field or role the entity takes in this table ## Optional
expr: The field that denotes that entity (transaction_id). ## Optional
Defaults to name if unspecified.
[config](/reference/resource-properties/config): Specify configurations for entity. ## Optional
[meta](/reference/resource-configs/meta): {<dictionary>} Set metadata for a resource and organize resources. Accepts plain text, spaces, and quotes. ## Optional
```
</VersionBlock>
<VersionBlock lastVersion="1.8">
```yaml
semantic_models:
- name: semantic_model_name
..rest of the semantic model config
entities:
- name: entity_name ## Required
type: Primary, or natural, or foreign, or unique ## Required
description: A description of the field or role the entity takes in this table ## Optional
expr: The field that denotes that entity (transaction_id). ## Optional
Defaults to name if unspecified.
```
</VersionBlock>
Here's an example of how to define entities in a semantic model:
<VersionBlock firstVersion="1.9">
```yaml
entities:
- name: transaction ## Required
type: Primary or natural or foreign or unique ## Required
- name: transaction
type: primary
expr: id_transaction
- name: order
type: foreign
expr: id_order
- name: user
type: foreign
expr: substring(id_order from 2)
entities:
- name: transaction
type:
description: A description of the field or role the entity takes in this table ## Optional
expr: The field that denotes that entity (transaction_id). ## Optional
expr: The field that denotes that entity (transaction_id).
Defaults to name if unspecified.
[config](/reference/resource-properties/config):
[meta](/reference/resource-configs/meta):
data_owner: "Finance team"
```
</VersionBlock>
<VersionBlock lastVersion="1.8">
Here's an example of how to define entities in a semantic model:
```yaml
entities:
- name: transaction
Expand All @@ -117,11 +167,18 @@ entities:
- name: user
type: foreign
expr: substring(id_order from 2)
entities:
- name: transaction
type:
description: A description of the field or role the entity takes in this table ## Optional
expr: The field that denotes that entity (transaction_id).
Defaults to name if unspecified.
```
</VersionBlock>
## Combine columns with a key
If a table doesn't have any key (like a primary key), use _surrogate combination_ to form a key that will help you identify a record by combining two columns. This applies to any [entity type](/docs/build/entities#entity-types). For example, you can combine `date_key` and `brand_code` from the `raw_brand_target_weekly` table to form a _surrogate key_. The following example creates a surrogate key by joining `date_key` and `brand_code` using a pipe (`|`) as a separator.
If a table doesn't have any key (like a primary key), use _surrogate combination_ to form a key that will help you identify a record by combining two columns. This applies to any [entity type](/docs/build/entities#entity-types). For example, you can combine `date_key` and `brand_code` from the `raw_brand_target_weekly` table to form a _surrogate key_. The following example creates a surrogate key by joining `date_key` and `brand_code` using a pipe (`|`) as a separator.

```yaml
Expand Down
Loading

0 comments on commit c34e68e

Please sign in to comment.