oso icon indicating copy to clipboard operation
oso copied to clipboard

Docs: How to write a timeseries metric

Open ravenac95 opened this issue 1 year ago • 3 comments

What is it?

We should have a guide to writing the new metrics models that we generate with sqlmesh.

Things to include:

  • Writing a normal aggregation
  • Approximately how joins work
  • Move custom macro docs to the new doc
  • How to write 1st, 2nd, and 3rd order rolling window metrics

ravenac95 avatar Oct 31 '24 18:10 ravenac95

See also #2094

ccerv1 avatar Jan 09 '25 00:01 ccerv1

I take it back, we still want to do this.

We should move the current "Write a data model in SQLMesh" and "Time Series Metrics Factory Deep Dive", combine them, and move them into the "Guides" section as reference material.

And we should write an actual tutorial on how to contribute to SQLMesh

ryscheng avatar Apr 16 '25 01:04 ryscheng

From @evanameyer1's latest experience:

  • Define the final metric you want to produce and create the new metric .sql file.
  • Determine/build the intermediate model, by working backwards from the metric to set up joins and transformations.
  • Make sure you're aggregating at least to the smallest grain needed (daily, weekly, etc.).
  • Add the metric query to the metrics factory, by creating the new query definition for your metric.
  • Add your new intermediate model to the allowed time series models list at the top of the factory if it's missing.
  • Test the model locally, by running oso local sqlmesh-test plan dev --start ... --end ... and check for errors, and fix any linter errors.
  • Validate model outputs locally, and then create PR and validate through CI

ccerv1 avatar Apr 28 '25 18:04 ccerv1