Skip to content

Auto-wrap ratio metric denominators in NULLIF#2147

Merged
shangyian merged 6 commits into
DataJunction:mainfrom
shangyian:nullif-ratios
May 19, 2026
Merged

Auto-wrap ratio metric denominators in NULLIF#2147
shangyian merged 6 commits into
DataJunction:mainfrom
shangyian:nullif-ratios

Conversation

@shangyian
Copy link
Copy Markdown
Collaborator

@shangyian shangyian commented May 18, 2026

Summary

Division-by-zero in metric SQL surfaces inconsistently across engines (Spark returns NaN, Trino raises an error, Postgres returns Infinity). The fix is to auto-wrap the right-hand side of every divide in the metric's combiner expression with NULLIF(denominator, 0), in two places:

  • Auto-built combiners from decomposing metrics like AVG
  • User-authored combiners when it's a user-defined ratio metric

A rate computed over zero observations is mathematically undefined; NULL represents that correctly and propagates safely through downstream aggregations. The auto-wrap normalizes divide-by-zero behavior across Spark/Trino/Postgres/Druid, and closes the class of "data unavailable" / NaN-percentile bugs without requiring every consumer to re-implement the same patch.

Test Plan

  • PR has an associated issue: #
  • make check passes
  • make test shows 100% unit test coverage

Deployment Plan

@netlify
Copy link
Copy Markdown

netlify Bot commented May 18, 2026

Deploy Preview for thriving-cassata-78ae72 canceled.

Name Link
🔨 Latest commit 5f68c3f
🔍 Latest deploy log https://app.netlify.com/projects/thriving-cassata-78ae72/deploys/6a0bc8fa97e1620008e1b6c2

@shangyian shangyian changed the title Add NULLIF wrappers to the denominator of ratio metrics Auto-wrap ratio metric denominators in NULLIF May 18, 2026
@shangyian shangyian marked this pull request as ready for review May 19, 2026 02:29
@shangyian shangyian merged commit 578b7f2 into DataJunction:main May 19, 2026
21 checks passed
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.

1 participant