Skip to content
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

Fix time spine validation error #354

Merged
merged 1 commit into from
Oct 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changes/unreleased/Fixes-20241010-142329.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
kind: Fixes
body: Fix time spine validation error
time: 2024-10-10T14:23:29.392029-05:00
custom:
Author: DevonFulcher
Issue: None
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

# dbt-semantic-interfaces

This repo contains the shared semantic classes, default validation, and tests designed to be used by both the dbt-core and MetricFlow projects. By centralizing these shared resources, we aim to maintain consistency and reduce code duplication across both projects.
This repo contains the shared semantic classes, default validation, and tests designed to be used by both the dbt-core and MetricFlow projects. By centralizing these shared resources, we aim to maintain consistency and reduce code duplication across both projects.

## Features
- Protocols for shared semantic classes: Define the interfaces and common attributes that must be implemented by the objects in both projects.
Expand Down
6 changes: 5 additions & 1 deletion dbt_semantic_interfaces/validations/time_spines.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,14 @@ def validate_manifest(semantic_manifest: SemanticManifestT) -> Sequence[Validati
if not semantic_manifest.semantic_models:
return issues

time_spines = semantic_manifest.project_configuration.time_spines
if not time_spines:
return issues

# Verify that there is only one time spine per granularity
time_spines_by_granularity: Dict[TimeGranularity, List[TimeSpine]] = {}
granularities_with_multiple_time_spines: Set[TimeGranularity] = set()
for time_spine in semantic_manifest.project_configuration.time_spines:
for time_spine in time_spines:
granularity = time_spine.primary_column.time_granularity
if granularity in time_spines_by_granularity:
time_spines_by_granularity[granularity].append(time_spine)
Expand Down
36 changes: 36 additions & 0 deletions tests/validations/test_time_spines.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,42 @@ def test_no_warning_for_legacy_time_spine() -> None: # noqa: D
assert len(issues.warnings) == 0


def test_no_time_spine_config() -> None: # noqa: D
validator = SemanticManifestValidator[PydanticSemanticManifest]()
semantic_manifest = PydanticSemanticManifest(
semantic_models=[
semantic_model_with_guaranteed_meta(
name="sum_measure",
dimensions=[
PydanticDimension(
name="dim",
type=DimensionType.TIME,
description="",
metadata=None,
type_params=PydanticDimensionTypeParams(time_granularity=TimeGranularity.SECOND),
)
],
entities=[PydanticEntity(name="entity", type=EntityType.PRIMARY)],
),
],
metrics=[
PydanticMetric(
name="metric",
description=None,
type=MetricType.SIMPLE,
type_params=PydanticMetricTypeParams(measure=PydanticMetricInputMeasure(name="sum_measure")),
),
],
project_configuration=PydanticProjectConfiguration(
time_spine_table_configurations=[],
time_spines=[],
),
)
issues = validator.validate_semantic_manifest(semantic_manifest)
assert not issues.has_blocking_issues
assert len(issues.warnings) == 0


def test_duplicate_time_spine_granularity() -> None: # noqa: D
validator = SemanticManifestValidator[PydanticSemanticManifest]()
semantic_manifest = PydanticSemanticManifest(
Expand Down
Loading