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

Provide resolved group-by-items to query-validation rules #1479

Merged
merged 1 commit into from
Oct 29, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -492,8 +492,12 @@ def _resolve_query(self, resolver_input_for_query: ResolverInputForQuery) -> Met
resolution_dag=resolution_dag,
resolver_input_for_query=resolver_input_for_query,
validation_rules=(
MetricTimeQueryValidationRule(self._manifest_lookup, resolver_input_for_query),
DuplicateMetricValidationRule(self._manifest_lookup, resolver_input_for_query),
MetricTimeQueryValidationRule(
self._manifest_lookup, resolver_input_for_query, resolve_group_by_item_result
),
DuplicateMetricValidationRule(
self._manifest_lookup, resolver_input_for_query, resolve_group_by_item_result
),
),
)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from __future__ import annotations

import typing
from abc import ABC, abstractmethod
from typing import Sequence

Expand All @@ -11,15 +12,22 @@
from metricflow_semantics.query.issues.issues_base import MetricFlowQueryResolutionIssueSet
from metricflow_semantics.query.resolver_inputs.query_resolver_inputs import ResolverInputForQuery

if typing.TYPE_CHECKING:
from metricflow_semantics.query.query_resolver import ResolveGroupByItemsResult


class PostResolutionQueryValidationRule(ABC):
"""A validation rule that runs after all query inputs have been resolved to specs."""

def __init__( # noqa: D107
self, manifest_lookup: SemanticManifestLookup, resolver_input_for_query: ResolverInputForQuery
self,
manifest_lookup: SemanticManifestLookup,
resolver_input_for_query: ResolverInputForQuery,
resolve_group_by_item_result: ResolveGroupByItemsResult,
) -> None:
self._manifest_lookup = manifest_lookup
self._resolver_input_for_query = resolver_input_for_query
self._resolve_group_by_item_result = resolve_group_by_item_result

@abstractmethod
def validate_metric_in_resolution_dag(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from __future__ import annotations

import typing
from dataclasses import dataclass
from typing import List, Sequence, Tuple

Expand Down Expand Up @@ -29,13 +30,14 @@
from metricflow_semantics.query.issues.parsing.scd_requires_metric_time import (
ScdRequiresMetricTimeIssue,
)
from metricflow_semantics.query.resolver_inputs.query_resolver_inputs import (
ResolverInputForQuery,
)
from metricflow_semantics.query.resolver_inputs.query_resolver_inputs import ResolverInputForQuery
from metricflow_semantics.query.validation_rules.base_validation_rule import PostResolutionQueryValidationRule
from metricflow_semantics.specs.instance_spec import InstanceSpec
from metricflow_semantics.specs.time_dimension_spec import TimeDimensionSpec

if typing.TYPE_CHECKING:
from metricflow_semantics.query.query_resolver import ResolveGroupByItemsResult


@dataclass(frozen=True)
class QueryItemsAnalysis:
Expand All @@ -57,9 +59,16 @@ class MetricTimeQueryValidationRule(PostResolutionQueryValidationRule):
"""

def __init__( # noqa: D107
self, manifest_lookup: SemanticManifestLookup, resolver_input_for_query: ResolverInputForQuery
self,
manifest_lookup: SemanticManifestLookup,
resolver_input_for_query: ResolverInputForQuery,
resolve_group_by_item_result: ResolveGroupByItemsResult,
) -> None:
super().__init__(manifest_lookup=manifest_lookup, resolver_input_for_query=resolver_input_for_query)
super().__init__(
manifest_lookup=manifest_lookup,
resolver_input_for_query=resolver_input_for_query,
resolve_group_by_item_result=resolve_group_by_item_result,
)

self._metric_time_specs = tuple(
TimeDimensionSpec.generate_possible_specs_for_time_dimension(
Expand Down
Loading