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

Consolidate Measure Time Spine Join Conditional Behavior Into MetricInputMeasureSpec #879

Merged
merged 1 commit into from
Nov 18, 2023

Conversation

plypaul
Copy link
Contributor

@plypaul plypaul commented Nov 16, 2023

Description

I found the DataflowPlanBuilder hard to follow in regards to when the measure would be joined to the time spine. There was conditional logic that depended on several parameters scattered throughout methods. This PR encapsulates the join condition in MetricInputMeasureSpec, and the consolidates filling out those fields when that spec is constructed. Once the behavior is encapsulated, the signature for methods _build_aggregated_measure_from_measure_source_node() can be simplified.

There's additional consolidation that can be done for cumulative measure parameters, but putting that off for now as consolidating this logic has been complex as it is. Also, there's a potential edge case with nested derived offset metrics that was found, but it is not addressed here.

@cla-bot cla-bot bot added the cla:yes label Nov 16, 2023
@plypaul plypaul force-pushed the plypaul--58.5--consolidate-into-measure-input-spec branch from 8bb0049 to 4eb5355 Compare November 16, 2023 04:06
@plypaul plypaul force-pushed the plypaul--58.4--refactor-dfpb branch from 0361b0e to 4c6ecb8 Compare November 16, 2023 04:21
Base automatically changed from plypaul--58.4--refactor-dfpb to main November 16, 2023 04:33
@plypaul plypaul force-pushed the plypaul--58.5--consolidate-into-measure-input-spec branch from 4eb5355 to 524e795 Compare November 16, 2023 04:34
@plypaul plypaul marked this pull request as ready for review November 16, 2023 05:53
@plypaul plypaul force-pushed the plypaul--58.5--consolidate-into-measure-input-spec branch from 524e795 to 4b2604d Compare November 16, 2023 19:57
Copy link
Contributor

@courtneyholcomb courtneyholcomb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me!

@@ -521,6 +532,20 @@ class LinkableSpecSet(Mergeable, SerializableDataclass):
time_dimension_specs: Tuple[TimeDimensionSpec, ...] = ()
entity_specs: Tuple[EntitySpec, ...] = ()

@property
def contains_metric_time(self) -> bool:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Helpful thank you!!

@@ -469,25 +472,33 @@ def reference(self) -> MetricReference:
return MetricReference(element_name=self.element_name)


@dataclass(frozen=True)
class MeasureCulminationDescription:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you mean Cumulation instead of Culmination? If not, why Culmination? 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I need to update the dictionary for my IDE:

image

But yeah, that's off.

query_contains_metric_time: bool,
culmination_description: Optional[MeasureCulminationDescription],
) -> MetricInputMeasureSpec:
"""Return the measure specs required to compute the base metric."""
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: update to singular measure spec

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated.

@@ -645,54 +677,87 @@ def build_computed_metrics_node(
metric_specs=[metric_spec],
)

def _measures_for_metric(
def _build_metric_input_measure_for_base_metric(
Copy link
Contributor

@courtneyholcomb courtneyholcomb Nov 17, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that we're about to add conversion measures, which will have multiple input metrics - so this might need to be rewritten by @WilliamDee

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 I need this, so we should sync to see whats the best path forward

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we mean multiple input measures, not metrics, but yes.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

im not gonna lie, i always get so confused visually and acoustically. Having to say/see metric input measure instead of just input measure messes with my eyes and ears thinking we're talking about input metrics

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated to input_measure.

Copy link
Contributor

@tlento tlento left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's what appears to be a bad conditional which may or may not matter if you coordinate merging with @courtneyholcomb's work on the nested offset metric fix, and the word culmination does not mean what it's referring to in the code.

Comment on lines 236 to 237
if (metric_spec.offset_to_grain is not None or metric_spec.offset_to_grain is not None) and (
metric_input_spec.offset_window is not None or metric_input_spec.offset_to_grain is not None
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks incorrect. Maybe this?

Suggested change
if (metric_spec.offset_to_grain is not None or metric_spec.offset_to_grain is not None) and (
metric_input_spec.offset_window is not None or metric_input_spec.offset_to_grain is not None
if (metric_spec.offset_window is not None or metric_spec.offset_to_grain is not None) and (
metric_input_spec.offset_window is not None or metric_input_spec.offset_to_grain is not None

I'm not sure it matters if @courtneyholcomb will remove this and fix up immediately afterwards but we might as well fix it in case something has to get reverted or deployed quickly.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated.

@@ -645,54 +677,87 @@ def build_computed_metrics_node(
metric_specs=[metric_spec],
)

def _measures_for_metric(
def _build_metric_input_measure_for_base_metric(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we mean multiple input measures, not metrics, but yes.

query_contains_metric_time=queried_linkable_specs.contains_metric_time,
child_metric_offset_window=metric_spec.offset_window,
child_metric_offset_to_grain=metric_spec.offset_to_grain,
culmination_description=MeasureCulminationDescription(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree with @courtneyholcomb, this name is odd. I'd go with:

cumulative_description=CumulativeMeasureDescription

Or else

accumulation_description=MeasureAccumulationDescription

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated.

@plypaul plypaul force-pushed the plypaul--58.5--consolidate-into-measure-input-spec branch 2 times, most recently from 98444f3 to 3995915 Compare November 18, 2023 01:11
@plypaul plypaul force-pushed the plypaul--58.5--consolidate-into-measure-input-spec branch from 3995915 to 274d987 Compare November 18, 2023 01:42
@plypaul plypaul merged commit 5506d0a into main Nov 18, 2023
8 checks passed
@plypaul plypaul deleted the plypaul--58.5--consolidate-into-measure-input-spec branch November 18, 2023 01:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants