Skip to content

[DBT] Emit OFFSET_SEMANTICS_LOSS when a DERIVED metric input uses offset_window/offset_to_grain - #371

Open
georgea-tk wants to merge 1 commit into
apache:mainfrom
georgea-tk:fix/offset-window-converter-issue
Open

[DBT] Emit OFFSET_SEMANTICS_LOSS when a DERIVED metric input uses offset_window/offset_to_grain#371
georgea-tk wants to merge 1 commit into
apache:mainfrom
georgea-tk:fix/offset-window-converter-issue

Conversation

@georgea-tk

Copy link
Copy Markdown

Summary

MSIToOssieConverter._resolve_derived reads alias, name and filter off each DERIVED metric input but never offset_window or offset_to_grain. A current-vs-offset comparison (e.g. a YoY metric with one input at the current period and one offset by a year) resolves both inputs to byte-identical SQL, so the derived expression becomes something like (SUM(x) - SUM(x)) / NULLIF(SUM(x), 0) * 100 — always zero, with ConverterResult.issues empty. A plausible-looking wrong number with no signal that anything was dropped.

This PR adds the minimum fix requested in #302: a new OFFSET_SEMANTICS_LOSS ConverterIssueType, emitted whenever a DERIVED metric declares an input with offset_window or offset_to_grain set, following the existing CUMULATIVE_SEMANTICS_LOSS pattern. It does not attempt to represent the offset semantics in the emitted expression — OSI/Ossie has no concept of a time offset today, so full representation is a separate spec question, not a converter one.

Related Issues

Fixes #302

Checklist

Specification

  • Spec changes are included in core-spec/ and follow the existing structure — N/A, no spec change
  • Spec changes have been discussed on the mailing list or in a linked issue — N/A
  • Breaking changes to the spec are clearly called out in the summary — N/A, no breaking change

Ontology

  • Ontology changes in ontology/ are consistent with spec changes — N/A
  • New or modified terms are defined and documented — N/A

Converters

  • Converter logic in converters/ is updated to reflect spec or ontology changes
  • New converters include tests under the converter's test directory — N/A (existing converter), but new tests added under converters/dbt/tests/

Validation

  • Validation rules in validation/ are updated if the spec changed — N/A
  • New validation cases are covered by tests — N/A

Documentation

  • docs/ is updated to reflect any user-facing changes — N/A, this is an internal ConverterIssue signal, no user-facing doc surface
  • New features or behaviors are documented with examples where appropriate — N/A
  • CONTRIBUTING.md is updated if the contribution process changed — N/A

Examples

  • examples/ are added or updated for any new spec constructs or converter support — N/A

Tests

  • All existing tests pass (pytest / CI green) — ran full converters/dbt suite locally, 102 passed
  • New functionality is covered by tests — 3 new tests: offset_window, offset_to_grain, and a negative case confirming an ordinary DERIVED metric with no offset does not emit the issue

Compliance

  • ASF license headers are present on all new source files — no new files, only edits to existing licensed files
  • No third-party dependencies are added without PMC/IPMC approval

…set_window/offset_to_grain

MSIToOssieConverter._resolve_derived reads alias, name and filter off each
DERIVED metric input but never offset_window or offset_to_grain. A
current-vs-offset comparison (e.g. YoY) resolves both inputs to
byte-identical SQL, silently producing an always-zero expression with no
ConverterIssue raised.

Emits OFFSET_SEMANTICS_LOSS, following the existing CUMULATIVE_SEMANTICS_LOSS
pattern, whenever a DERIVED metric declares an input with offset_window or
offset_to_grain set. This is the minimum fix requested in apache#302: it turns a
silent wrong answer into a visible, gateable issue. Representing the offset
semantics themselves is a separate spec question, since OSI/Ossie currently
has nothing to carry a time offset.

Fixes apache#302

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Comment on lines +113 to +119
if metric.type is MetricType.DERIVED and any(
input_metric.offset_window or input_metric.offset_to_grain
for input_metric in metric.type_params.metrics or []
):
issues.append(
ConverterIssue(issue_type=ConverterIssueType.OFFSET_SEMANTICS_LOSS, element_name=metric.name)
)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I just found https://github.com/apache/ossie/pull/318/changes by @fanruan-tuco, which has some elements that could be adopted. I like the stronger-typed message from this PR and the recursive approach from the other PR, which could capture more cases.

Perhaps, this would be a good opportunity to collaborate & merge the two PRs?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

msi_to_osi silently drops offset_window / offset_to_grain on DERIVED metric inputs, producing constant-zero expressions

2 participants