Repository navigation
fix(dbt): warn on non-portable metric semantics - #318
fanruan-tuco wants to merge 2 commits into
Conversation
|
@fanruan-tuco can you please rebase and resolve conflicts? Thanks! |
| issues.append( | ||
| ConverterIssue(issue_type=ConverterIssueType.CUMULATIVE_SEMANTICS_LOSS, element_name=metric.name) | ||
| ) | ||
| elif _has_nonportable_semantics(metric, metric_index): |
There was a problem hiding this comment.
This new branch records a NON_PORTABLE_METRIC_SEMANTICS issue but doesn't change control flow: the next line (expr = self._resolve_metric_expression(...), unchanged) still runs and emits the lossy expression regardless.
I verified against the example in the PR (month_over_month_growth = (cur - pre) / pre): the emitted expression is (SUM(orders.amount) - SUM(orders.amount)) / SUM(orders.amount), always 0. The output document carries no marker of the problem, only a side-channel entry in result.issues: a caller that doesn't check issues ships an always-zero metric silently.
Should this branch continue/skip emitting the metric (like CONVERSION_METRIC_DROPPED above) instead of failing through?
| visiting: Optional[set[str]] = None, | ||
| ) -> bool: | ||
| """Return whether a metric uses semantics Ossie cannot represent.""" | ||
| if metric.type is MetricType.CUMULATIVE: |
There was a problem hiding this comment.
This only special-cases CUMULATIVE. A DERIVED/RATIO metric that depends on a CONVERSION-type metric return False here (not portable-safe, just unrecognized), so convert() proceeds into _unresolve_metric_expression, which raises an unhandled RuntimeError ("Unexpected CONVERSION metric in expression resolver") and aborts conversion of the entire manifest.
Maybe worth adding a MetricType.CONVERSION case here too.
Summary
MetricFlow time-context semantics such as cumulative metrics, windows, time spine behavior, and offset-period inputs cannot be represented faithfully in Ossie. This change emits
NON_PORTABLE_METRIC_SEMANTICSinstead of silently producing a lossy conversion.It also checks derived and ratio dependencies recursively, including cases such as:
Fixes #317
Validation
uv run pytest -qinconverters/dbt: 103 passed.