Skip to content

Commit

Permalink
Add empty manifest check for SavedQueryDependencyResolver.
Browse files Browse the repository at this point in the history
  • Loading branch information
plypaul committed Sep 25, 2024
1 parent 488a694 commit 9817eac
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import logging
from dataclasses import dataclass
from typing import Tuple
from typing import Optional, Tuple

from dbt_semantic_interfaces.protocols import SemanticManifest
from dbt_semantic_interfaces.references import (
Expand Down Expand Up @@ -34,9 +34,19 @@ class SavedQueryDependencyResolver:

def __init__(self, semantic_manifest: SemanticManifest) -> None: # noqa: D107
self._semantic_manifest = semantic_manifest
self._query_parser = MetricFlowQueryParser(SemanticManifestLookup(semantic_manifest))
# TODO: There seems to be issues with an empty manifest, so doing this check for now.
self._query_parser: Optional[MetricFlowQueryParser] = None
if len(semantic_manifest.semantic_models) > 0:
self._query_parser = MetricFlowQueryParser(SemanticManifestLookup(semantic_manifest))

def _resolve_dependencies(self, saved_query_name: str) -> SavedQueryDependencySet:
if self._query_parser is None:
logger.warning(
"Trying to resolve the dependencies of a saved query when the provided semantic manifest does not "
"contain semantic models is unexpected. Returning an empty set."
)
return SavedQueryDependencySet(())

parse_result = self._query_parser.parse_and_validate_saved_query(
saved_query_parameter=SavedQueryParameter(saved_query_name),
where_filter=None,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from __future__ import annotations

import pytest
from dbt_semantic_interfaces.implementations.project_configuration import PydanticProjectConfiguration
from dbt_semantic_interfaces.implementations.semantic_manifest import (
PydanticSemanticManifest,
)
Expand All @@ -23,3 +24,14 @@ def test_saved_query_dependency_resolver(resolver: SavedQueryDependencyResolver)
SemanticModelReference(semantic_model_name="bookings_source"),
SemanticModelReference(semantic_model_name="listings_latest"),
)


def test_empty_manifest() -> None: # noqa: D103
"""In case the manifest is empty, checks that the resolver can be created."""
SavedQueryDependencyResolver(
PydanticSemanticManifest(
semantic_models=[],
metrics=[],
project_configuration=PydanticProjectConfiguration(),
)
)

0 comments on commit 9817eac

Please sign in to comment.