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

Expose Saved Queries on MFEngine #933

Merged
merged 2 commits into from
Dec 7, 2023
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
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,
)
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ dependencies = [
"PyYAML~=6.0",
"click>=7.1.2",
"dbt-core~=1.7.0",
"dbt-semantic-interfaces~=0.4.0",
"dbt-semantic-interfaces==0.4.2.dev0",
"graphviz>=0.18.2, <0.21",
"halo~=0.0.31",
"more-itertools>=8.10.0, <10.2.0",
Expand Down