Skip to content

Commit

Permalink
Add element type property to LinkableElement interface (#1226)
Browse files Browse the repository at this point in the history
The LinkableElement interface is used in cases where we have a
set of LinkableElements undifferentiated by underlying type.
In predicate pushdown, this happens with where specs that reference
some set of linkable elements but store them in an undifferentiated
collection.

In practice, we need to know not just the object type, but the more
refined LinkableElementType in order to apply the pushdown evaluation
logic, as time dimensions and categorical dimensions need to be
considered in a distinct way.

This makes the relevant property available in the parent interface
so we can access it directly.
  • Loading branch information
tlento authored May 24, 2024
1 parent d995502 commit ff012cc
Showing 1 changed file with 28 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from __future__ import annotations

import logging
from abc import ABC
from abc import ABC, abstractmethod
from dataclasses import dataclass
from enum import Enum
from typing import FrozenSet, Optional, Sequence, Tuple
Expand Down Expand Up @@ -98,7 +98,11 @@ class SemanticModelJoinPathElement:
class LinkableElement(SemanticModelDerivation, SerializableDataclass, ABC):
"""An entity / dimension that may have been joined by entities."""

pass
@property
@abstractmethod
def element_type(self) -> LinkableElementType:
"""The LinkableElementType describing what this instance represents."""
raise NotImplementedError


@dataclass(frozen=True)
Expand All @@ -116,15 +120,19 @@ class LinkableDimension(LinkableElement, SerializableDataclass):
date_part: Optional[DatePart]

@property
def path_key(self) -> ElementPathKey: # noqa: D102
if self.dimension_type is DimensionType.CATEGORICAL:
element_type = LinkableElementType.DIMENSION
else:
element_type = LinkableElementType.TIME_DIMENSION
@override
def element_type(self) -> LinkableElementType:
return (
LinkableElementType.DIMENSION
if self.dimension_type is DimensionType.CATEGORICAL
else LinkableElementType.TIME_DIMENSION
)

@property
def path_key(self) -> ElementPathKey: # noqa: D102
return ElementPathKey(
element_name=self.element_name,
element_type=element_type,
element_type=self.element_type,
entity_links=self.entity_links,
time_granularity=self.time_granularity,
date_part=self.date_part,
Expand Down Expand Up @@ -156,10 +164,15 @@ class LinkableEntity(LinkableElement, SerializableDataclass):
entity_links: Tuple[EntityReference, ...]
join_path: SemanticModelJoinPath

@property
@override
def element_type(self) -> LinkableElementType:
return LinkableElementType.ENTITY

@property
def path_key(self) -> ElementPathKey: # noqa: D102
return ElementPathKey(
element_name=self.element_name, element_type=LinkableElementType.ENTITY, entity_links=self.entity_links
element_name=self.element_name, element_type=self.element_type, entity_links=self.entity_links
)

@property
Expand Down Expand Up @@ -199,6 +212,11 @@ def __post_init__(self) -> None:
"""
assert {LinkableElementProperty.METRIC, LinkableElementProperty.JOINED}.issubset(self.properties)

@property
@override
def element_type(self) -> LinkableElementType:
return LinkableElementType.METRIC

@property
def element_name(self) -> str: # noqa: D102
return self.reference.element_name
Expand All @@ -207,7 +225,7 @@ def element_name(self) -> str: # noqa: D102
def path_key(self) -> ElementPathKey: # noqa: D102
return ElementPathKey(
element_name=self.element_name,
element_type=LinkableElementType.METRIC,
element_type=self.element_type,
entity_links=self.join_path.entity_links,
metric_subquery_entity_links=self.metric_subquery_entity_links,
)
Expand Down

0 comments on commit ff012cc

Please sign in to comment.