-
Notifications
You must be signed in to change notification settings - Fork 97
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
Fill nulls for multi-metric queries #850
Merged
Merged
Changes from 1 commit
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
4de5d57
Update MetricInstance to take a singular defined_from object instead …
courtneyholcomb 5cd869e
Spelling fix
courtneyholcomb e8e1b17
Fill nulls post-metric join for multi-metric queries
courtneyholcomb 304b730
Changelog
courtneyholcomb 6abdf1c
Add method to get YAML-defined input measures
courtneyholcomb affea74
Add new test case & update source data
courtneyholcomb b8bc8dc
Write output tests for filling nulls
courtneyholcomb aa32059
Update Databricks snapshots
courtneyholcomb 6545bc1
Rename YAML -> config
courtneyholcomb File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,13 @@ | ||
from __future__ import annotations | ||
|
||
import logging | ||
from typing import Dict, FrozenSet, List, Sequence | ||
from typing import Dict, FrozenSet, List, Optional, Sequence | ||
|
||
from dbt_semantic_interfaces.enum_extension import assert_values_exhausted | ||
from dbt_semantic_interfaces.implementations.filters.where_filter import PydanticWhereFilterIntersection | ||
from dbt_semantic_interfaces.implementations.metric import PydanticMetricTimeWindow | ||
from dbt_semantic_interfaces.protocols import WhereFilter | ||
from dbt_semantic_interfaces.protocols.metric import Metric, MetricType | ||
from dbt_semantic_interfaces.protocols.metric import Metric, MetricInputMeasure, MetricType | ||
from dbt_semantic_interfaces.protocols.semantic_manifest import SemanticManifest | ||
from dbt_semantic_interfaces.references import MetricReference | ||
|
||
|
@@ -105,6 +106,23 @@ def add_metric(self, metric: Metric) -> None: | |
) | ||
self._metrics[metric_reference] = metric | ||
|
||
def yaml_input_measure_for_metric(self, metric_reference: MetricReference) -> Optional[MetricInputMeasure]: | ||
"""Get input measure defined in the metric YAML, if exists. | ||
|
||
When SemanticModel is constructed, input measures from input metrics are added to the list of input measures | ||
for a metric. Here, use rules about metric types to determine which input measures were defined in the YAML: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Then here we can replace |
||
- Simple & cumulative metrics require one input measure, and can't take any input metrics. | ||
- Derived & ratio metrics take no input measures, only input metrics. | ||
""" | ||
metric = self.get_metric(metric_reference=metric_reference) | ||
if metric.type is MetricType.CUMULATIVE or metric.type is MetricType.SIMPLE: | ||
assert len(metric.input_measures) == 1, "Simple and cumulative metrics should have one input measure." | ||
return metric.input_measures[0] | ||
elif metric.type is MetricType.RATIO or metric.type is MetricType.DERIVED: | ||
return None | ||
else: | ||
assert_values_exhausted(metric.type) | ||
|
||
def measures_for_metric( | ||
self, | ||
metric_reference: MetricReference, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice! Super nitty but can we rename this away from yaml? YAML makes me grumpy. More importantly, there's no guarantee that the input is defined in YAML (although in practice that is how it works today).
Maybe something like
direct_input_measure_for_metric
orconfigured_input_measure_for_metric
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated!