|
3 | 3 | import pytest
|
4 | 4 |
|
5 | 5 | from core.dbt.contracts.graph.manifest import Manifest
|
6 |
| -from core.dbt.contracts.graph.nodes import Metric, ModelNode |
7 | 6 | from dbt.artifacts.resources.types import NodeType
|
8 | 7 | from dbt.artifacts.resources.v1.metric import (
|
9 | 8 | CumulativeTypeParams,
|
10 | 9 | MetricTimeWindow,
|
11 | 10 | MetricTypeParams,
|
12 | 11 | )
|
| 12 | +from dbt.artifacts.resources.v1.model import ModelConfig, TimeSpine |
| 13 | +from dbt.constants import LEGACY_TIME_SPINE_MODEL_NAME |
| 14 | +from dbt.contracts.files import FileHash |
| 15 | +from dbt.contracts.graph.nodes import ColumnInfo, DependsOn, Metric, ModelNode |
13 | 16 | from dbt.contracts.graph.semantic_manifest import SemanticManifest
|
14 | 17 | from dbt_semantic_interfaces.type_enums import TimeGranularity
|
15 | 18 | from dbt_semantic_interfaces.type_enums.metric_type import MetricType
|
@@ -55,6 +58,57 @@ def test_require_yaml_configuration_for_mf_time_spines(
|
55 | 58 | assert sm_manifest.validate()
|
56 | 59 | assert patched_deprecations.warn.call_count == 1
|
57 | 60 |
|
| 61 | + def test_metricflow_time_spine_non_day_grain_deprecation_warning( |
| 62 | + self, manifest: Manifest, metricflow_time_spine_model: ModelNode |
| 63 | + ): |
| 64 | + """Test that a metricflow_time_spine with non-day grain does not trigger deprecation warning.""" |
| 65 | + # Create a metricflow_time_spine model with HOUR granularity |
| 66 | + metricflow_time_spine_hour = ModelNode( |
| 67 | + name=LEGACY_TIME_SPINE_MODEL_NAME, |
| 68 | + database="dbt", |
| 69 | + schema="analytics", |
| 70 | + alias=LEGACY_TIME_SPINE_MODEL_NAME, |
| 71 | + resource_type=NodeType.Model, |
| 72 | + unique_id="model.test.metricflow_time_spine", |
| 73 | + fqn=["test", "metricflow_time_spine"], |
| 74 | + package_name="test", |
| 75 | + refs=[], |
| 76 | + sources=[], |
| 77 | + metrics=[], |
| 78 | + depends_on=DependsOn(), |
| 79 | + config=ModelConfig(), |
| 80 | + tags=[], |
| 81 | + path="metricflow_time_spine.sql", |
| 82 | + original_file_path="metricflow_time_spine.sql", |
| 83 | + meta={}, |
| 84 | + language="sql", |
| 85 | + raw_code="SELECT DATEADD(hour, ROW_NUMBER() OVER (ORDER BY 1), '2020-01-01'::timestamp) as ts_hour", |
| 86 | + checksum=FileHash.empty(), |
| 87 | + relation_name="", |
| 88 | + columns={ |
| 89 | + "ts_hour": ColumnInfo( |
| 90 | + name="ts_hour", |
| 91 | + description="", |
| 92 | + meta={}, |
| 93 | + data_type="timestamp", |
| 94 | + constraints=[], |
| 95 | + quote=None, |
| 96 | + tags=[], |
| 97 | + granularity=TimeGranularity.HOUR, |
| 98 | + ) |
| 99 | + }, |
| 100 | + time_spine=TimeSpine(standard_granularity_column="ts_hour"), |
| 101 | + ) |
| 102 | + |
| 103 | + with patch("dbt.contracts.graph.semantic_manifest.get_flags") as patched_get_flags, patch( |
| 104 | + "dbt.contracts.graph.semantic_manifest.deprecations" |
| 105 | + ) as patched_deprecations: |
| 106 | + patched_get_flags.return_value.require_yaml_configuration_for_mf_time_spines = False |
| 107 | + manifest.nodes[metricflow_time_spine_hour.unique_id] = metricflow_time_spine_hour |
| 108 | + sm_manifest = SemanticManifest(manifest) |
| 109 | + assert sm_manifest.validate() |
| 110 | + assert patched_deprecations.warn.call_count == 0 |
| 111 | + |
58 | 112 | @pytest.mark.parametrize(
|
59 | 113 | "metric_type_params, num_warns, should_error, flag_value",
|
60 | 114 | [
|
|
0 commit comments