[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 dbt functionality, rather than a Big Idea better suited to a discussion
Describe the feature
The name of the date field that is output from the metrics.calculate macro varies depending on the time grain specified - for example, when grain is set to 'year', the date field in the output is called 'date_year'. While this is no doubt useful for end-users to understand the time grain specified, there are some situations where optionally allowing this field to be aliased could be beneficial.
For example:
I connect my BI tool to a metrics query where grain = 'year'
I build a chart using the 'date_year' field
I then dynamically swap the grain value to 'month' with a front-end parameter that updates the query
The chart is still pointing at a field called 'date_year', not 'date_month', so the chart throws an error because the 'date_year' field no longer exists
Having the option to alias the date field would get around this problem
Describe alternatives you've considered
It's possible to circumvent this issue with a query like
select $1 as date, * from {{ metrics.calculate( ... ) }}
where you make an assumption that the date field will always be in the first field position. However as @callum-mcdata pointed out, for some configurations this will not be true. Additionally, relying on field positions for processes is never a best practice.
Who will this benefit?
This will benefit anybody using or creating an integration with dbt Metrics, allowing their integrations to be more stable. This issue arose for me in Tableau for example, so any and all Tableau users connecting to a Metrics query could benefit from this feature and avoid a potentially brittle workaround. For anybody building an integration, it could make their integration more stable by avoiding workarounds.
Is this your first time submitting a feature request?
Describe the feature
The name of the date field that is output from the metrics.calculate macro varies depending on the time grain specified - for example, when grain is set to 'year', the date field in the output is called 'date_year'. While this is no doubt useful for end-users to understand the time grain specified, there are some situations where optionally allowing this field to be aliased could be beneficial.
For example:
Having the option to alias the date field would get around this problem
Describe alternatives you've considered
It's possible to circumvent this issue with a query like
select $1 as date, * from {{ metrics.calculate( ... ) }}
where you make an assumption that the date field will always be in the first field position. However as @callum-mcdata pointed out, for some configurations this will not be true. Additionally, relying on field positions for processes is never a best practice.
Who will this benefit?
This will benefit anybody using or creating an integration with dbt Metrics, allowing their integrations to be more stable. This issue arose for me in Tableau for example, so any and all Tableau users connecting to a Metrics query could benefit from this feature and avoid a potentially brittle workaround. For anybody building an integration, it could make their integration more stable by avoiding workarounds.
Are you interested in contributing this feature?
No
Anything else?
https://getdbt.slack.com/archives/C02CCBBBR1D/p1669746957363789