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

Lowercase all names passed into StructuredLinkableSpecName #1394

Merged
merged 2 commits into from
Sep 5, 2024
Merged
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
@@ -1,20 +1,16 @@
from __future__ import annotations

import logging
from dataclasses import dataclass
from typing import Optional, Tuple

from dbt_semantic_interfaces.type_enums.date_part import DatePart
from dbt_semantic_interfaces.type_enums.time_granularity import TimeGranularity

from metricflow_semantics.time.granularity import ExpandedTimeGranularity

DUNDER = "__"

logger = logging.getLogger(__name__)


@dataclass(frozen=True)
class StructuredLinkableSpecName:
"""Parse a qualified name into different parts.

Expand All @@ -24,37 +20,18 @@ class StructuredLinkableSpecName:
granularity: TimeGranularity.WEEK
"""

entity_link_names: Tuple[str, ...]
element_name: str
time_granularity_name: Optional[str] = None
date_part: Optional[DatePart] = None

def __post_init__(self) -> None:
"""Post init method to ensure all name values are lower-case.

This implies that all values in the TimeGranularity enumeration must be lower-case.
"""
assert self.element_name.lower() == self.element_name, (
f"Element name {self.element_name} is not all lower-case. This should have been addressed at model "
"parse time!"
)
assert all([link_name.lower() == link_name for link_name in self.entity_link_names]), (
f"Found entity link name that includes upper-case letters. Entity link names: {self.entity_link_names}. "
"This should have been addressed at model parse time!"
)

if self.time_granularity_name:
is_standard_name = ExpandedTimeGranularity.is_standard_granularity_name(self.time_granularity_name)
if is_standard_name:
follow_up = (
"This indicates a bug where someone added a non-lowercase value to the TimeGranularity "
"enum in dbt-semantic-interfaces!"
)
else:
follow_up = "This should have been addressed at model parse time!"
assert (
self.time_granularity_name.lower() == self.time_granularity_name
), f"The time_granularity_name {self.time_granularity_name} includes upper-case letters. {follow_up}"
def __init__(
self,
entity_link_names: Tuple[str, ...],
element_name: str,
time_granularity_name: Optional[str] = None,
date_part: Optional[DatePart] = None,
) -> None:
"""Set attributes, ensuring names are lowercased."""
self.entity_link_names = tuple([entity_link_name.lower() for entity_link_name in entity_link_names])
self.element_name = element_name.lower()
self.time_granularity_name = time_granularity_name.lower() if time_granularity_name else None
courtneyholcomb marked this conversation as resolved.
Show resolved Hide resolved
self.date_part = date_part

@staticmethod
def from_name(qualified_name: str) -> StructuredLinkableSpecName:
Expand Down
Loading