Skip to content

Commit

Permalink
Expose saved queries in MFEngine
Browse files Browse the repository at this point in the history
  • Loading branch information
courtneyholcomb committed Dec 7, 2023
1 parent 5ac91ab commit 79093d1
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
9 changes: 8 additions & 1 deletion metricflow/engine/metricflow_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
from metricflow.dataset.convert_semantic_model import SemanticModelToDataSetConverter
from metricflow.dataset.dataset import DataSet
from metricflow.dataset.semantic_model_adapter import SemanticModelDataSet
from metricflow.engine.models import Dimension, Entity, Measure, Metric
from metricflow.engine.models import Dimension, Entity, Measure, Metric, SavedQuery
from metricflow.engine.time_source import ServerTimeSource
from metricflow.errors.errors import ExecutionException
from metricflow.execution.execution_plan import ExecutionPlan, SqlQuery
Expand Down Expand Up @@ -679,6 +679,13 @@ def list_metrics(self) -> List[Metric]: # noqa: D
for metric in metrics
]

@log_call(module_name=__name__, telemetry_reporter=_telemetry_reporter)
def list_saved_queries(self) -> List[SavedQuery]: # noqa: D
return [
SavedQuery.from_pydantic(saved_query)
for saved_query in self._semantic_manifest_lookup.semantic_manifest.saved_queries
]

@log_call(module_name=__name__, telemetry_reporter=_telemetry_reporter)
def get_dimension_values( # noqa: D
self,
Expand Down
28 changes: 28 additions & 0 deletions metricflow/engine/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@
from dbt_semantic_interfaces.protocols.metadata import Metadata
from dbt_semantic_interfaces.protocols.metric import Metric as SemanticManifestMetric
from dbt_semantic_interfaces.protocols.metric import MetricInputMeasure, MetricType, MetricTypeParams
from dbt_semantic_interfaces.protocols.saved_query import (
SavedQuery as SemanticManifestSavedQuery,
)
from dbt_semantic_interfaces.protocols.saved_query import (
SavedQueryQueryParams,
)
from dbt_semantic_interfaces.protocols.where_filter import WhereFilterIntersection
from dbt_semantic_interfaces.transformations.add_input_metric_measures import AddInputMetricMeasuresRule
from dbt_semantic_interfaces.type_enums.aggregation_type import AggregationType
Expand Down Expand Up @@ -144,3 +150,25 @@ class Measure:
description: Optional[str] = None
expr: Optional[str] = None
agg_params: Optional[MeasureAggregationParameters] = None


@dataclass(frozen=True)
class SavedQuery:
"""Dataclass representation of a SavedQuery."""

name: str
description: Optional[str]
label: Optional[str]
query_params: SavedQueryQueryParams
metadata: Optional[Metadata]

@classmethod
def from_pydantic(cls, pydantic_saved_query: SemanticManifestSavedQuery) -> SavedQuery:
"""Build from pydantic SavedQuery object."""
return cls(
name=pydantic_saved_query.name,
description=pydantic_saved_query.description,
label=pydantic_saved_query.label,
query_params=pydantic_saved_query.query_params,
metadata=pydantic_saved_query.metadata,
)

0 comments on commit 79093d1

Please sign in to comment.