-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
85 additions
and
1 deletion.
There are no files selected for viewing
42 changes: 42 additions & 0 deletions
42
dbt_semantic_interfaces/experimental/saved_query_dependency_resolver.py
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 |
---|---|---|
@@ -0,0 +1,42 @@ | ||
from dataclasses import dataclass | ||
from typing import Optional, Tuple | ||
|
||
from dbt_semantic_interfaces.protocols import SemanticManifest | ||
from dbt_semantic_interfaces.references import ( | ||
SavedQueryReference, | ||
SemanticModelReference, | ||
) | ||
|
||
|
||
@dataclass(frozen=True) | ||
class SavedQueryDependencySet: | ||
"""The dependencies of a saved query. | ||
The primary use case is to handle creation of the cache item associated with the saved query. The dependencies | ||
listed in this class must be up-to-date before the cache associated with the saved query can be created. Otherwise, | ||
running the export / creating the cache may create a cache item that is out-of-date / unusable. | ||
""" | ||
|
||
# A human-readable description for logging purposes. | ||
description: Optional[str] | ||
# The semantic models that the saved query depends on. | ||
semantic_model_references: Tuple[SemanticModelReference, ...] | ||
|
||
|
||
class SavedQueryDependencyResolver: | ||
"""Resolves the dependencies of a saved query. Also see `SavedQueryDependencySet`.""" | ||
|
||
def __init__(self, semantic_manifest: SemanticManifest) -> None: # noqa: D | ||
self._semantic_manifest = semantic_manifest | ||
|
||
def resolve_dependencies(self, saved_query_reference: SavedQueryReference) -> SavedQueryDependencySet: | ||
"""Return the dependencies of the given saved query in the manifest.""" | ||
return SavedQueryDependencySet( | ||
description=( | ||
f"Dependencies for saved query {repr(saved_query_reference.saved_query_name)} include all semantic " | ||
f"models as a temporary result until the complete implementation is in place." | ||
), | ||
semantic_model_references=tuple( | ||
sorted(semantic_model.reference for semantic_model in self._semantic_manifest.semantic_models) | ||
), | ||
) |
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
Empty file.
35 changes: 35 additions & 0 deletions
35
tests/experimental/test_saved_query_dependency_resolver.py
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 |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import pytest | ||
|
||
from dbt_semantic_interfaces.experimental.saved_query_dependency_resolver import ( | ||
SavedQueryDependencyResolver, | ||
) | ||
from dbt_semantic_interfaces.implementations.semantic_manifest import ( | ||
PydanticSemanticManifest, | ||
) | ||
from dbt_semantic_interfaces.references import ( | ||
SavedQueryReference, | ||
SemanticModelReference, | ||
) | ||
|
||
|
||
@pytest.fixture(scope="session") | ||
def resolver( # noqa: D | ||
simple_semantic_manifest__with_primary_transforms: PydanticSemanticManifest, | ||
) -> SavedQueryDependencyResolver: | ||
return SavedQueryDependencyResolver(simple_semantic_manifest__with_primary_transforms) | ||
|
||
|
||
def test_saved_query_dependency_resolver(resolver: SavedQueryDependencyResolver) -> None: # noqa: D | ||
dependency_set = resolver.resolve_dependencies(SavedQueryReference("p0_booking")) | ||
assert tuple(dependency_set.semantic_model_references) == ( | ||
SemanticModelReference(semantic_model_name="accounts_source"), | ||
SemanticModelReference(semantic_model_name="bookings_source"), | ||
SemanticModelReference(semantic_model_name="companies"), | ||
SemanticModelReference(semantic_model_name="id_verifications"), | ||
SemanticModelReference(semantic_model_name="listings_latest"), | ||
SemanticModelReference(semantic_model_name="lux_listing_mapping"), | ||
SemanticModelReference(semantic_model_name="revenue"), | ||
SemanticModelReference(semantic_model_name="users_ds_source"), | ||
SemanticModelReference(semantic_model_name="users_latest"), | ||
SemanticModelReference(semantic_model_name="views_source"), | ||
) |