-
Notifications
You must be signed in to change notification settings - Fork 977
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add 1.8 and lower version timespine #6261
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
5b586b8
re-add older versions
mirnawong1 7d6df71
Merge branch 'current' into update-timespine
mirnawong1 d6a5ce4
courtney's feedback
mirnawong1 d89f6ce
Merge branch 'current' into update-timespine
mirnawong1 ddd2ff7
versionblock hourly
mirnawong1 a2d28cd
courtney's feedback
mirnawong1 5685dce
Merge branch 'current' into update-timespine
mirnawong1 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,15 @@ | ||
--- | ||
title: MetricFlow time spine | ||
id: metricflow-time-spine | ||
description: "MetricFlow expects a default timespine table called metricflow_time_spine" | ||
description: "MetricFlow expects a default time spine table called metricflow_time_spine" | ||
sidebar_label: "MetricFlow time spine" | ||
tags: [Metrics, Semantic Layer] | ||
--- | ||
<VersionBlock firstVersion="1.9"> | ||
|
||
It's common in analytics engineering to have a date dimension or "time spine" table as a base table for different types of time-based joins and aggregations. The structure of this table is typically a base column of daily or hourly dates, with additional columns for other time grains, like fiscal quarters, defined based on the base column. You can join other tables to the time spine on the base column to calculate metrics like revenue at a point in time, or to aggregate to a specific time grain. | ||
<!-- this whole section is for 1.9 and higher + Versionless --> | ||
|
||
It's common in analytics engineering to have a date dimension or "time spine" table as a base table for different types of time-based joins and aggregations. The structure of this table is typically a base column of daily or hourly dates, with additional columns for other time grains, like fiscal quarters, defined based on the base column. You can join other tables to the time spine on the base column to calculate metrics like revenue at a point in time, or to aggregate to a specific time grain. | ||
|
||
MetricFlow requires you to define at least one dbt model which provides a time-spine, and then specify (in YAML) the columns to be used for time-based joins. MetricFlow will join against the time-spine model for the following types of metrics and dimensions: | ||
|
||
|
@@ -74,6 +76,7 @@ This example creates a time spine at an hourly grain and a daily grain: `time_sp | |
<Lightbox src="/img/time_spines.png" width="50%" title="Time spine directory structure" /> | ||
<!-- | ||
<VersionBlock lastVersion="1.8"> | ||
<File name="models/_models.yml"> | ||
|
@@ -98,6 +101,7 @@ models: | |
</File> | ||
</VersionBlock> | ||
--> | ||
- This example configuration shows a time spine model called `time_spine_hourly` and `time_spine_daily`. It sets the time spine configurations under the `time_spine` key. | ||
- The `standard_granularity_column` is the column that maps to one of our [standard granularities](/docs/build/dimensions?dimension=time_gran). This column must be set under the `columns` key and should have a grain that is finer or equal to any custom granularity columns defined in the same model. | ||
|
@@ -290,13 +294,165 @@ and date_hour < dateadd(day, 30, current_timestamp()) | |
</File> | ||
|
||
|
||
</VersionBlock> | ||
|
||
<VersionBlock lastVersion="1.8"> | ||
|
||
<!-- this whole section is for 1.8 and and lower --> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is the v1.8 and lower section |
||
|
||
MetricFlow uses a time spine table to construct cumulative metrics. By default, MetricFlow expects the time spine table to be named `metricflow_time_spine` and doesn't support using a different name. For supported granularities, refer to the [dimensions](/docs/build/dimensions?dimension=time_gran#time) page. | ||
|
||
To create this table, you need to create a model in your dbt project called `metricflow_time_spine` and add the following code: | ||
|
||
### Daily | ||
|
||
<VersionBlock lastVersion="1.6"> | ||
<File name='metricflow_time_spine.sql'> | ||
|
||
```sql | ||
{{ | ||
config( | ||
materialized = 'table', | ||
) | ||
}} | ||
with days as ( | ||
{{ | ||
dbt_utils.date_spine( | ||
'day', | ||
"to_date('01/01/2000','mm/dd/yyyy')", | ||
"to_date('01/01/2025','mm/dd/yyyy')" | ||
) | ||
}} | ||
), | ||
final as ( | ||
select cast(date_day as date) as date_day | ||
from days | ||
) | ||
select * from final | ||
-- filter the time spine to a specific range | ||
where date_day > dateadd(year, -4, current_timestamp()) | ||
and date_hour < dateadd(day, 30, current_timestamp()) | ||
``` | ||
</File> | ||
</VersionBlock> | ||
|
||
<VersionBlock firstVersion="1.7"> | ||
<File name='metricflow_time_spine.sql'> | ||
|
||
|
||
```sql | ||
{{ | ||
config( | ||
materialized = 'table', | ||
) | ||
}} | ||
with days as ( | ||
{{ | ||
dbt.date_spine( | ||
'day', | ||
"to_date('01/01/2000','mm/dd/yyyy')", | ||
"to_date('01/01/2025','mm/dd/yyyy')" | ||
) | ||
}} | ||
), | ||
final as ( | ||
select cast(date_day as date) as date_day | ||
from days | ||
) | ||
select * from final | ||
where date_day > dateadd(year, -4, current_timestamp()) | ||
and date_hour < dateadd(day, 30, current_timestamp()) | ||
``` | ||
|
||
</File> | ||
</VersionBlock> | ||
|
||
### Daily (BigQuery) | ||
|
||
Use this model if you're using BigQuery. BigQuery supports `DATE()` instead of `TO_DATE()`: | ||
|
||
<VersionBlock lastVersion="1.6"> | ||
|
||
<File name="metricflow_time_spine.sql"> | ||
|
||
```sql | ||
{{config(materialized='table')}} | ||
with days as ( | ||
{{dbt_utils.date_spine( | ||
'day', | ||
"DATE(2000,01,01)", | ||
"DATE(2025,01,01)" | ||
) | ||
}} | ||
), | ||
final as ( | ||
select cast(date_day as date) as date_day | ||
from days | ||
) | ||
select * | ||
from final | ||
-- filter the time spine to a specific range | ||
where date_day > dateadd(year, -4, current_timestamp()) | ||
and date_hour < dateadd(day, 30, current_timestamp()) | ||
``` | ||
</File> | ||
</VersionBlock> | ||
|
||
<VersionBlock firstVersion="1.7"> | ||
|
||
<File name="metricflow_time_spine.sql"> | ||
|
||
```sql | ||
{{config(materialized='table')}} | ||
with days as ( | ||
{{dbt.date_spine( | ||
'day', | ||
"DATE(2000,01,01)", | ||
"DATE(2025,01,01)" | ||
) | ||
}} | ||
), | ||
final as ( | ||
select cast(date_day as date) as date_day | ||
from days | ||
) | ||
select * | ||
from final | ||
-- filter the time spine to a specific range | ||
where date_day > dateadd(year, -4, current_timestamp()) | ||
and date_hour < dateadd(day, 30, current_timestamp()) | ||
``` | ||
|
||
</File> | ||
</VersionBlock> | ||
|
||
You only need to include the `date_day` column in the table. MetricFlow can handle broader levels of detail, but finer grains are only supported in versions 1.9 and higher. | ||
|
||
</VersionBlock> | ||
|
||
|
||
## Custom calendar <Lifecycle status="Preview"/> | ||
|
||
<VersionBlock lastVersion="1.8"> | ||
|
||
The ability to configure custom calendars, such as a fiscal calendar, is available in [dbt Cloud Versionless](/docs/dbt-versions/upgrade-dbt-version-in-cloud#versionless) or dbt Core [v1.9 and higher](/docs/dbt-versions/core). | ||
The ability to configure custom calendars, such as a fiscal calendar, is available in [dbt Cloud Versionless](/docs/dbt-versions/versionless-cloud) or dbt Core [v1.9 and higher](/docs/dbt-versions/core). | ||
|
||
To access this feature, [upgrade to Versionless](/docs/dbt-versions/upgrade-dbt-version-in-cloud#versionless) or your dbt Core version to v1.9 or higher. | ||
|
||
To access this feature, [upgrade to Versionless](/docs/dbt-versions/versionless-cloud) or your dbt Core version to v1.9 or higher. | ||
</VersionBlock> | ||
|
||
<VersionBlock firstVersion="1.9"> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this commenting out the version block below?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes it is! but we dont need this yaml for 1.8 and lower right?