dbt-labs / dbt-labs/metricflow
[SL-3394] [Feature] Allow specifying an alias for each group-by and metric in the saved query
- Dominant language
- Python
- Stars
- 1.8k
- Forks
- 202
- Avg merge
- 1d 8h
- Merged PRs (30d)
- 14
Description
### Is this your first time submitting a feature request?
- [X] I have read the [expectations for open source contributors](https://docs.getdbt.com/docs/contributing/oss-expectations)
- [X] I have searched the existing issues, and I could not find an existing issue for this feature
- [X] I am requesting a straightforward extension of existing metricflow functionality, rather than a Big Idea better suited to a discussion
### Describe the feature
If you have a saved query like this (from [here](https://docs.getdbt.com/docs/build/saved-queries#configure-exports)):
```
saved_queries:
- name: order_metrics
description: Relevant order metrics
query_params:
metrics:
- orders
- large_order
- food_orders
- order_total
group_by:
- Entity('order_id')
- TimeDimension('metric_time', 'day')
- Dimension('customer__customer_name')
- ... # Additional group_by
where:
- "{{TimeDimension('metric_time')}} > current_timestamp - interval '1 week'"
- ... # Additional where clauses
exports:
- name: order_metrics
config:
export_as: table # Options available: table, view
schema: YOUR_SCHEMA # Optional - defaults to deployment schema
alias: SOME_TABLE_NAME # Optional - defaults to Export name
```
then your export table will have MetricFlow-specific column names, something like this:
| order_id | metric_time__day | customer__customer_name | orders | large_order | food_orders | order_total | | | |
|----------|------------------|-------------------------|--------|-------------|-------------|-------------|---|---|---|
| | | | | | | | | | |
Since the person who writes the saved query and needs the export might now have full control over the naming conventions used in the semantic model, they may end up with badly named columns (from their perspective). Currently, they would be able to correct the columns by... maintaining a view on top of the export?
How about allowing to configure an alias for every metric and group by in the saved query? Something like this:
```
saved_queries:
- name: order_metrics
description: Relevant order metrics
query_params:
metrics:
- orders
alias: count_orders
- large_order
alias: count_large_orders
- food_orders
- order_total
group_by:
- Entity('order_id')
- TimeDimension('metric_time', 'day')
alias: calendar_date
- Dimension('customer__customer_name')
alias: customer_name
- ... # Additional group_by
where:
- "{{TimeDimension('metric_time')}} > current_timestamp - interval '1 week'"
- ... # Additional where clauses
exports:
- name: order_metrics
config:
export_as: table # Options available: table, view
schema: YOUR_SCHEMA # Optional - defaults to deployment schema
alias: SOME_TABLE_NAME # Optional - defaults to Export name
```
### Describe alternatives you've considered
An independent view on top of the export?
### Who will this benefit?
Anyone using saved queries
### Are you interested in contributing this feature?
Happy to test it out in preview
### Anything else?
_No response_
[SL-3394](https://linear.app/dbt-labs/issue/SL-3394/[feature]-allow-specifying-an-alias-for-each-group-by-and-metric-in)
Contributor guide
Assessment
This issue has not been assessed yet.