oso
oso copied to clipboard
Docs: How to write a timeseries metric
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
See also #2094
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
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