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

Adjust application of cumulative_type_params to smooth out release process #298

Merged
merged 3 commits into from
Jun 20, 2024
Merged
Show file tree
Hide file tree
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
Expand Up @@ -17,6 +17,9 @@
from dbt_semantic_interfaces.transformations.convert_median import (
ConvertMedianToPercentileRule,
)
from dbt_semantic_interfaces.transformations.cumulative_type_params import (
SetCumulativeTypeParamsRule,
)
from dbt_semantic_interfaces.transformations.names import LowerCaseNamesRule
from dbt_semantic_interfaces.transformations.proxy_measure import CreateProxyMeasureRule
from dbt_semantic_interfaces.transformations.rule_set import (
Expand Down Expand Up @@ -50,6 +53,7 @@ def secondary_rules(self) -> Sequence[SemanticManifestTransformRule[PydanticSema
ConvertCountToSumRule(),
ConvertMedianToPercentileRule(),
AddInputMetricMeasuresRule(),
SetCumulativeTypeParamsRule(),
)

@property
Expand Down
7 changes: 5 additions & 2 deletions dbt_semantic_interfaces/validations/metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
validate_safely,
)

# Temp: undo once cumulative_type_params are supported in MF
CUMULATIVE_TYPE_PARAMS_SUPPORTED = False


class CumulativeMetricRule(SemanticManifestValidationRule[SemanticManifestT], Generic[SemanticManifestT]):
"""Checks that cumulative sum metrics are configured properly."""
Expand All @@ -42,7 +45,7 @@ def _validate_cumulative_sum_metric_params(metric: Metric) -> List[ValidationIss
for field in ("window", "grain_to_date"):
type_params_field_value = getattr(metric.type_params, field)
# Warn that the old type_params structure has been deprecated.
if type_params_field_value:
if type_params_field_value and CUMULATIVE_TYPE_PARAMS_SUPPORTED:
issues.append(
ValidationWarning(
context=metric_context,
Expand All @@ -62,7 +65,7 @@ def _validate_cumulative_sum_metric_params(metric: Metric) -> List[ValidationIss
type_params_field_value
and cumulative_type_params_field_value
and cumulative_type_params_field_value != type_params_field_value
):
) and CUMULATIVE_TYPE_PARAMS_SUPPORTED:
issues.append(
ValidationError(
context=metric_context,
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "dbt-semantic-interfaces"
version = "0.6.1.dev0"
version = "0.6.1"
description = 'The shared semantic layer definitions that dbt-core and MetricFlow use'
readme = "README.md"
requires-python = ">=3.8"
Expand Down
37 changes: 23 additions & 14 deletions tests/validations/test_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
TimeGranularity,
)
from dbt_semantic_interfaces.validations.metrics import (
CUMULATIVE_TYPE_PARAMS_SUPPORTED,
ConversionMetricRule,
CumulativeMetricRule,
DerivedMetricRule,
Expand Down Expand Up @@ -690,17 +691,25 @@ def test_cumulative_metrics() -> None: # noqa: D
)

build_issues = validation_results.all_issues
for issue in build_issues:
print(issue.message)
assert len(build_issues) == 8
expected_substr1 = "Both window and grain_to_date set for cumulative metric. Please set one or the other."
expected_substr2 = "Got differing values for `window`"
expected_substr3 = "Got differing values for `grain_to_date`"
expected_substr4 = "Cumulative `type_params.window` field has been moved and will soon be deprecated."
expected_substr5 = "Cumulative `type_params.grain_to_date` field has been moved and will soon be deprecated."
missing_error_strings = set()
for expected_str in [expected_substr1, expected_substr2, expected_substr3, expected_substr4, expected_substr5]:
if not any(actual_str.as_readable_str().find(expected_str) != -1 for actual_str in build_issues):
missing_error_strings.add(expected_str)
assert len(missing_error_strings) == 0, "Failed to match one or more expected issues: "
f"{missing_error_strings} in {set([x.as_readable_str() for x in build_issues])}"
if CUMULATIVE_TYPE_PARAMS_SUPPORTED:
assert len(build_issues) == 8
expected_substr1 = "Both window and grain_to_date set for cumulative metric. Please set one or the other."
expected_substr2 = "Got differing values for `window`"
expected_substr3 = "Got differing values for `grain_to_date`"
expected_substr4 = "Cumulative `type_params.window` field has been moved and will soon be deprecated."
expected_substr5 = "Cumulative `type_params.grain_to_date` field has been moved and will soon be deprecated."
missing_error_strings = set()
for expected_str in [expected_substr1, expected_substr2, expected_substr3, expected_substr4, expected_substr5]:
if not any(actual_str.as_readable_str().find(expected_str) != -1 for actual_str in build_issues):
missing_error_strings.add(expected_str)
assert len(missing_error_strings) == 0, "Failed to match one or more expected issues: "
f"{missing_error_strings} in {set([x.as_readable_str() for x in build_issues])}"
else:
assert len(build_issues) == 1
expected_substr1 = "Both window and grain_to_date set for cumulative metric. Please set one or the other."
Comment on lines +707 to +709
Copy link
Collaborator

Choose a reason for hiding this comment

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

Ew. At least this is temporary.... I don't know that we have much choice given the way this test is structured.

If, instead, we could split the old-style test out from the new style we could just do pytest.mark.skip on the new bit and remove the validator from the DEFAULT_RULES list for now, but I don't know how worthwhile that is. It'll make this test cleaner, so it's not a total waste of time.

missing_error_strings = set()
for expected_str in [expected_substr1]:
if not any(actual_str.as_readable_str().find(expected_str) != -1 for actual_str in build_issues):
missing_error_strings.add(expected_str)
assert len(missing_error_strings) == 0, "Failed to match one or more expected issues: "
f"{missing_error_strings} in {set([x.as_readable_str() for x in build_issues])}"
Loading