Skip to content

Commit

Permalink
Associated import and method changes in the rest of the codebase.
Browse files Browse the repository at this point in the history
  • Loading branch information
plypaul committed Apr 26, 2024
1 parent 9cb1650 commit 5ed211e
Show file tree
Hide file tree
Showing 30 changed files with 269 additions and 100 deletions.
4 changes: 2 additions & 2 deletions metricflow-semantics/metricflow_semantics/instances.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,17 @@

from metricflow_semantics.aggregation_properties import AggregationState
from metricflow_semantics.specs.column_assoc import ColumnAssociation
from metricflow_semantics.specs.group_by_metric_spec import GroupByMetricSpec
from metricflow_semantics.specs.spec_classes import (
DimensionSpec,
EntitySpec,
GroupByMetricSpec,
InstanceSpec,
InstanceSpecSet,
MeasureSpec,
MetadataSpec,
MetricSpec,
TimeDimensionSpec,
)
from metricflow_semantics.specs.spec_set import InstanceSpecSet

# Type for the specification used in the instance.
SpecT = TypeVar("SpecT", bound=InstanceSpec)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,8 @@
)
from metricflow_semantics.specs.spec_classes import (
InstanceSpec,
InstanceSpecSet,
InstanceSpecSetTransform,
)
from metricflow_semantics.specs.spec_set import InstanceSpecSet, InstanceSpecSetTransform, group_spec_by_type


class DunderNamingScheme(QueryItemNamingScheme):
Expand All @@ -37,7 +36,7 @@ def date_part_suffix(date_part: DatePart) -> str:

@override
def input_str(self, instance_spec: InstanceSpec) -> Optional[str]:
spec_set = InstanceSpecSet.from_specs((instance_spec,))
spec_set = group_spec_by_type(instance_spec)

for time_dimension_spec in spec_set.time_dimension_specs:
# From existing comment in StructuredLinkableSpecName:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@
from metricflow_semantics.specs.patterns.metric_pattern import MetricSpecPattern
from metricflow_semantics.specs.spec_classes import (
InstanceSpec,
InstanceSpecSet,
)
from metricflow_semantics.specs.spec_set import group_spec_by_type


class MetricNamingScheme(QueryItemNamingScheme):
"""A naming scheme for metrics."""

@override
def input_str(self, instance_spec: InstanceSpec) -> Optional[str]:
spec_set = InstanceSpecSet.from_specs((instance_spec,))
spec_set = group_spec_by_type(instance_spec)
names = tuple(spec.element_name for spec in spec_set.metric_specs)

if len(names) != 1:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
from dbt_semantic_interfaces.type_enums.date_part import DatePart
from typing_extensions import override

from metricflow_semantics.specs.spec_classes import InstanceSpec, InstanceSpecSet, InstanceSpecSetTransform
from metricflow_semantics.specs.spec_classes import InstanceSpec
from metricflow_semantics.specs.spec_set import InstanceSpecSet, InstanceSpecSetTransform, group_spec_by_type


class ObjectBuilderNameConverter:
Expand Down Expand Up @@ -139,9 +140,7 @@ def transform(self, spec_set: InstanceSpecSet) -> Sequence[str]:

@staticmethod
def input_str_from_spec(instance_spec: InstanceSpec) -> str: # noqa: D102
names = ObjectBuilderNameConverter._ObjectBuilderNameTransform().transform(
InstanceSpecSet.from_specs((instance_spec,))
)
names = ObjectBuilderNameConverter._ObjectBuilderNameTransform().transform(group_spec_by_type(instance_spec))

if len(names) != 1:
raise RuntimeError(f"Did not get exactly 1 name from {instance_spec}. Got {names}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
from metricflow_semantics.mf_logging.pretty_print import mf_pformat
from metricflow_semantics.model.semantics.linkable_element_set import LinkableElementSet
from metricflow_semantics.naming.object_builder_scheme import ObjectBuilderNamingScheme
from metricflow_semantics.specs.spec_classes import InstanceSpecSet, LinkableSpecSet
from metricflow_semantics.specs.linkable_spec_set import LinkableSpecSet
from metricflow_semantics.specs.spec_set import InstanceSpecSet

logger = logging.getLogger(__name__)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
ValidLinkableSpecResolver,
)
from metricflow_semantics.model.semantics.semantic_model_join_evaluator import MAX_JOIN_HOPS
from metricflow_semantics.specs.spec_set import InstanceSpecSet
from metricflow_semantics.test_helpers.config_helpers import MetricFlowTestConfiguration
from metricflow_semantics.test_helpers.snapshot_helpers import (
assert_linkable_element_set_snapshot_equal,
Expand Down Expand Up @@ -193,15 +194,16 @@ def test_linkable_element_set_as_spec_set(
double up on the .as_spec_set calls here. Yes, this is lazy. No, I don't care to make another helper to
do snapshot comparisons on LinkableSpecSets.
"""
linkable_spec_set = simple_model_spec_resolver.get_linkable_element_set_for_measure(
MeasureReference(element_name="listings"),
with_any_of=LinkableElementProperty.all_properties(),
without_any_of=frozenset({}),
).as_spec_set

linkable_spec_set = InstanceSpecSet.create_from_specs(
simple_model_spec_resolver.get_linkable_element_set_for_measure(
MeasureReference(element_name="listings"),
with_any_of=LinkableElementProperty.all_properties(),
without_any_of=frozenset({}),
).specs
)
assert_spec_set_snapshot_equal(
request=request,
mf_test_configuration=mf_test_configuration,
set_id="set0",
spec_set=linkable_spec_set.as_spec_set,
spec_set=linkable_spec_set,
)
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def test_local_linked_elements_for_metric( # noqa: D103
with_any_property=frozenset({LinkableElementProperty.LOCAL_LINKED}),
without_any_property=frozenset({LinkableElementProperty.DERIVED_TIME_GRANULARITY}),
)
sorted_specs = sorted(linkable_elements.as_spec_set.as_tuple, key=lambda x: x.qualified_name)
sorted_specs = sorted(linkable_elements.specs, key=lambda x: x.qualified_name)
assert_object_snapshot_equal(
request=request,
mf_test_configuration=mf_test_configuration,
Expand Down Expand Up @@ -140,7 +140,7 @@ def test_linkable_elements_for_no_metrics_query(
LinkableElementProperty.DERIVED_TIME_GRANULARITY,
}
)
sorted_specs = sorted(linkable_elements.as_spec_set.as_tuple, key=lambda x: x.qualified_name)
sorted_specs = sorted(linkable_elements.specs, key=lambda x: x.qualified_name)
assert_object_snapshot_equal(
request=request,
mf_test_configuration=mf_test_configuration,
Expand Down
Loading

0 comments on commit 5ed211e

Please sign in to comment.