Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
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
Prev Previous commit
Next Next commit
Migrate checked_agg_time_dimension to `checked_agg_time_dimension_f…
…or_measure`

DSI 0.1.0dev10 moved `checked_agg_time_dimension` from the `Measure`
protocol to the `SemanticModel` protocol as `checked_agg_time_dimension_for_measure`.
This finishes a change where for a given measure either the `Measure.agg_time_dimension`
or the measure's parent `SemanticModel.defaults.agg_time_dimension` needs to be
set, instead of always require the measure's `Measure.agg_time_dimension`.
  • Loading branch information
QMalcolm committed Jul 12, 2023
commit 6a0af562c4a2bac70974b4c73b0814cb2a2d80df
24 changes: 24 additions & 0 deletions core/dbt/contracts/graph/nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
MeasureReference,
LinkableElementReference,
SemanticModelReference,
TimeDimensionReference,
)
from dbt_semantic_interfaces.references import MetricReference as DSIMetricReference
from dbt_semantic_interfaces.type_enums import MetricType, TimeGranularity
Expand Down Expand Up @@ -1542,6 +1543,29 @@ def depends_on_nodes(self):
def depends_on_macros(self):
return self.depends_on.macros

def checked_agg_time_dimension_for_measure(
self, measure_reference: MeasureReference
) -> TimeDimensionReference:
measure: Optional[Measure] = None
for measure in self.measures:
if measure.reference == measure_reference:
measure = measure

assert (
measure is not None
), f"No measure with name ({measure_reference.element_name}) in semantic_model with name ({self.name})"

if self.defaults is not None:
default_agg_time_dimesion = self.defaults.agg_time_dimension

agg_time_dimension_name = measure.agg_time_dimension or default_agg_time_dimesion
assert agg_time_dimension_name is not None, (
f"Aggregation time dimension for measure {measure.name} is not set! This should either be set directly on "
f"the measure specification in the model, or else defaulted to the primary time dimension in the data "
f"source containing the measure."
)
return TimeDimensionReference(element_name=agg_time_dimension_name)


# ====================================
# Patches
Expand Down
7 changes: 0 additions & 7 deletions core/dbt/contracts/graph/semantic_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,13 +142,6 @@ class Measure(dbtClassMixin):
non_additive_dimension: Optional[NonAdditiveDimension] = None
agg_time_dimension: Optional[str] = None

@property
def checked_agg_time_dimension(self) -> TimeDimensionReference:
if self.agg_time_dimension is not None:
return TimeDimensionReference(element_name=self.agg_time_dimension)
else:
raise Exception("Measure is missing agg_time_dimension!")

@property
def reference(self) -> MeasureReference:
return MeasureReference(element_name=self.name)