Skip to main content
You will end with a new source that metrics can read, checked against its columns and guarded by a test. The steps use a CSV file in the sample project from the quickstart; step 5 swaps the file for a database table.

1. Add the file

Copy the file into data/ and name it under sources in hatchmark.yaml. The key is the name metrics use, in lowercase snake_case.
path is relative to hatchmark.yaml. Parquet, JSON, DuckDB and SQLite files and cloud storage work the same way with their own type; data sources lists every option.

2. Look at the columns

It prints each column’s type and kind, null and distinct counts, the range of time and number columns, and the first rows. These are the types metrics will see, so check that dates read as time and amounts as number. A column that reads as text usually holds a stray value, such as n/a in an amount; fix the export, or read it with a database query that casts it.

3. Ask it a question

Every source is a table named after it, and the query runs read-only over the same data build reads. Use it to confirm the numbers you expect before you define metrics on them.

4. Check the project

Check reads the new source’s columns and reports any metric or block that names one it doesn’t have. Next, define metrics on it.

5. Or connect a database

A database source names an environment variable that holds the connection string, never the string itself:
  • mysql, sqlserver and bigquery work the same way; database sources has each connection string.
  • posthog reads the result of a HogQL query in PostHog; see Use PostHog data.
  • query in place of table runs one SELECT in the database, to cast, filter or join first.
  • max_age reuses the local copy of the rows while it is younger than an hour, so dev doesn’t fetch on every save.
  • check runs without the variable and only warns that it couldn’t read the columns, so it can run in CI. build needs the rows and must run where the database is reachable.

6. Guard it with a test

A row-count test fails when an export comes in short or a column fills with nulls:
It exits 1 when a test fails, so it fits a CI step. See row-count tests.