Skip to content

Commit

Permalink
Change assertions to warnings for evaluation.
Browse files Browse the repository at this point in the history
  • Loading branch information
tlento committed Sep 3, 2024
1 parent d35ebaf commit 136fb41
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -242,10 +242,12 @@ def _add_semantic_model(self, semantic_model: SemanticModel) -> None:
semantic_models_for_dimension = self._dimension_index.get(dim.reference, []) + [semantic_model]
self._dimension_index[dim.reference] = semantic_models_for_dimension

assert StructuredLinkableSpecName.from_name(dim.name).is_element_name, (
f"Dimension name `{dim.name}` contains annotations, but this name should be the plain element name "
"from the original model. This should have been blocked by validation!"
)
if not StructuredLinkableSpecName.from_name(dim.name).is_element_name:
# TODO: [custom granularity] change this to an assertion once we're sure there aren't exceptions
logger.warning(
f"Dimension name `{dim.name}` contains annotations, but this name should be the plain element name "
"from the original model. This should have been blocked by validation!"
)

# TODO: Construct these specs correctly. All of the time dimension specs have the default granularity
self._dimension_ref_to_spec[dim.time_dimension_reference or dim.reference] = (
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from __future__ import annotations

import logging
from dataclasses import dataclass
from hashlib import sha1
from typing import Any, Sequence, Tuple
Expand All @@ -13,6 +14,8 @@
from metricflow_semantics.specs.time_dimension_spec import TimeDimensionSpec
from metricflow_semantics.sql.sql_column_type import SqlColumnType

logger = logging.getLogger(__file__)


def hash_items(items: Sequence[SqlColumnType]) -> str:
"""Produces a hash from a list of strings."""
Expand All @@ -36,10 +39,12 @@ class NonAdditiveDimensionSpec(SerializableDataclass):

def __post_init__(self) -> None:
"""Post init validator to ensure names with double-underscores are not allowed."""
assert self.name.find(DUNDER) == -1, (
f"Non-additive dimension spec references a dimension name `{self.name}`, with added annotations, but it "
"should be a simple element name reference. This should have been blocked by model validation!"
)
# TODO: [custom granularity] change this to an assertion once we're sure there aren't exceptions
if not self.name.find(DUNDER) == -1:
logger.warning(
f"Non-additive dimension spec references a dimension name `{self.name}`, with added annotations, but it "
"should be a simple element name reference. This should have been blocked by model validation!"
)

@property
def bucket_hash(self) -> str:
Expand Down
10 changes: 6 additions & 4 deletions metricflow/dataflow/builder/dataflow_plan_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -401,10 +401,12 @@ def _build_conversion_metric_output_node(
descendent_filter_specs=metric_spec.filter_specs,
queried_linkable_specs=queried_linkable_specs,
)
assert StructuredLinkableSpecName.from_name(conversion_type_params.entity).is_element_name, (
f"Found additional annotations in type param entity name `{conversion_type_params.entity}`, which should "
"be a simple element name reference. This should have been blocked by model validation!"
)
# TODO: [custom granularity] change this to an assertion once we're sure there aren't exceptions
if not StructuredLinkableSpecName.from_name(conversion_type_params.entity).is_element_name:
logger.warning(
f"Found additional annotations in type param entity name `{conversion_type_params.entity}`, which "
"should be a simple element name reference. This should have been blocked by model validation!"
)
entity_spec = EntitySpec(element_name=conversion_type_params.entity, entity_links=())
logger.info(
f"For conversion metric {metric_spec},\n"
Expand Down

0 comments on commit 136fb41

Please sign in to comment.