dbt-labs / dbt-labs/metricflow

Enable support for roles via the `entity` property in identifiers

Open
#240 3 comments 1 reaction 1 assignee Claimed by @plypaul View on GitHub
backlog enhancement
Dominant language
Python
Stars
1.8k
Forks
202
Avg merge
1d 8h
Merged PRs (30d)
14

Description

There are many cases where identifiers represent entities in the world, but those entities can play different roles. For example, you might have a marketplace where users can be either buyers or sellers, or a lodging service where users can be guests or hosts.

The config spec for supporting this is to have each identifier `name` represent the role, and an optional `entity` value represent the specific entity. If no `entity` value is provided, the `name` represents both role and identity. We have test configs with a [basic user account entity setup](https://github.com/transform-data/metricflow/blob/main/metricflow/test/fixtures/model_yamls/simple_model/data_sources/users_latest.yaml#L19-L22) and a [corresponding entity/role mapping in a separate data source](https://github.com/transform-data/metricflow/blob/main/metricflow/test/fixtures/model_yamls/simple_model/data_sources/bookings_source.yaml#L60-L67).

The linked specifications theoretically allow you to write a query like:

```
mf query --metrics bookings --dimensions guest__home_state_latest
```

That should resolve the role of `guest` (based on the identifier name) to the entity `user` (based on entity value). So the underlying SQL would be the equivalent of:

```
SELECT b.guest__home_state_latest, a.bookings
FROM (
SELECT guest_id AS guest, SUM(1) AS bookings
FROM bookings_source
GROUP BY 1
) a
LEFT OUTER JOIN users_latest b
-- role value joined to corresponding entity value
ON a.guest = b.user
```

Today it throws an exception because the logic to process this resolution has not yet been implemented, and we insist on joining `ON a.guest = b.guest` but there is no `guest` entity in the model.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.