Skip to content

Commit

Permalink
/* PR_START p--short-term-perf 27 */ Add validation step for measures.
Browse files Browse the repository at this point in the history
  • Loading branch information
plypaul committed Oct 28, 2024
1 parent ffebc13 commit 5a5c7fa
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from typing import Sequence

from dbt_semantic_interfaces.protocols import WhereFilterIntersection
from dbt_semantic_interfaces.references import MetricReference
from dbt_semantic_interfaces.references import MeasureReference, MetricReference

from metricflow_semantics.model.semantic_manifest_lookup import SemanticManifestLookup
from metricflow_semantics.query.group_by_item.resolution_path import MetricFlowQueryResolutionPath
Expand All @@ -29,6 +29,18 @@ def __init__( # noqa: D107
self._resolver_input_for_query = resolver_input_for_query
self._resolve_group_by_item_result = resolve_group_by_item_result

@abstractmethod
def validate_measure_in_resolution_dag(
self,
measure_reference: MeasureReference,
resolution_path: MetricFlowQueryResolutionPath,
) -> MetricFlowQueryResolutionIssueSet:
"""Given a measure that exists in a resolution DAG, check that the query is valid.
This is called for each measure of a base metric as the resolution DAG is traversed.
"""
raise NotImplementedError

@abstractmethod
def validate_metric_in_resolution_dag(
self,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from typing import Sequence

from dbt_semantic_interfaces.protocols import WhereFilterIntersection
from dbt_semantic_interfaces.references import MetricReference
from dbt_semantic_interfaces.references import MeasureReference, MetricReference
from typing_extensions import override

from metricflow_semantics.query.group_by_item.resolution_path import MetricFlowQueryResolutionPath
Expand Down Expand Up @@ -49,3 +49,11 @@ def validate_query_in_resolution_dag(
)

return MetricFlowQueryResolutionIssueSet.empty_instance()

@override
def validate_measure_in_resolution_dag(
self,
measure_reference: MeasureReference,
resolution_path: MetricFlowQueryResolutionPath,
) -> MetricFlowQueryResolutionIssueSet:
return MetricFlowQueryResolutionIssueSet.empty_instance()
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from dbt_semantic_interfaces.naming.keywords import METRIC_TIME_ELEMENT_NAME
from dbt_semantic_interfaces.protocols import Metric, WhereFilterIntersection
from dbt_semantic_interfaces.references import (
MeasureReference,
MetricReference,
TimeDimensionReference,
)
Expand Down Expand Up @@ -227,3 +228,11 @@ def validate_query_in_resolution_dag(
resolution_path: MetricFlowQueryResolutionPath,
) -> MetricFlowQueryResolutionIssueSet:
return MetricFlowQueryResolutionIssueSet.empty_instance()

@override
def validate_measure_in_resolution_dag(
self,
measure_reference: MeasureReference,
resolution_path: MetricFlowQueryResolutionPath,
) -> MetricFlowQueryResolutionIssueSet:
return MetricFlowQueryResolutionIssueSet.empty_instance()
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,18 @@ def _default_handler(self, node: GroupByItemResolutionNode) -> MetricFlowQueryRe

@override
def visit_measure_node(self, node: MeasureGroupByItemSourceNode) -> MetricFlowQueryResolutionIssueSet:
return self._default_handler(node)
with self._path_from_start_node_tracker.track_node_visit(node) as current_traversal_path:
issue_sets_to_merge = [parent_node.accept(self) for parent_node in node.parent_nodes]

for validation_rule in self._validation_rules:
issue_sets_to_merge.append(
validation_rule.validate_measure_in_resolution_dag(
measure_reference=node.measure_reference,
resolution_path=current_traversal_path,
)
)

return MetricFlowQueryResolutionIssueSet.merge_iterable(issue_sets_to_merge)

@override
def visit_metric_node(self, node: MetricGroupByItemResolutionNode) -> MetricFlowQueryResolutionIssueSet:
Expand Down

0 comments on commit 5a5c7fa

Please sign in to comment.