Help us shape the future of Go! Take the 2026 Go Developer Survey

check

package
v0.6.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 14, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package check turns a model's `tests:` into SQL.

A TEST IS A SELECT THAT RETURNS VIOLATING ROWS. Zero rows is a pass, and there is nothing else to interpret: no exit code to read, no count to compare against a threshold somebody has to remember, and no second language to learn. It is dbt's shape and it is the right one -- the query that reports the failure is a query somebody can paste into a console and keep narrowing.

NOTHING HERE IS ON THE DIALECT INTERFACE except Literal, which is already there because it measurably differs. The four tests are standard SQL and both warehouses run the same text; adding a method per test kind would be an interface describing this package rather than describing a warehouse.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Check

type Check struct {
	Model  string
	Kind   string
	Column string

	// Count is the query whose single value is how many rows break it.
	Count string

	// Sample is the query whose single value is ONE offending value, and it
	// is empty when the kind has none worth showing: every row that breaks
	// `not_null` breaks it by being NULL, and printing NULL back teaches
	// nobody anything.
	Sample string
}

Check is one assertion, ready to run.

func For

func For(d dialect.Dialect, m model.Model, t model.Test) ([]Check, error)

For is every check one `tests:` entry makes.

A SLICE, because `not_null: [a, b, c]` is three checks and a failure has to name THE column. One check over three columns would report "not_null failed on orders", which is the report that sends somebody to read the model.

type Failure

type Failure struct {
	Check
	Rows int64
	// Value is one offending value, when the kind has one worth showing.
	// Empty for not_null, and empty when the sample query returned a NULL
	// -- a duplicated NULL cannot happen, so an empty one here means the
	// column held an empty string, which is a thing somebody needs to see
	// as "" rather than as nothing.
	Value string
}

Failure is a check that found rows.

type Result

type Result struct {
	Ran    int
	Failed []Failure
}

Result is the run.

func Run

func Run(ctx context.Context, d dialect.Dialect, conn dialect.Conn,
	p *project.Project, order []string) (Result, error)

Run runs every test of every model in `order`.

IT DOES NOT STOP AT THE FIRST FAILURE, which is the opposite of Build and right for the opposite reason. A build that keeps going puts models on top of a relation that is not what their SQL assumed; a test run that stops hands somebody one problem at a time across four round trips to a warehouse. The whole report, once.

A query the warehouse REFUSES is still an error and does stop it: that is not a model failing its test, it is this package having written SQL the warehouse will not take, and continuing would bury it under results.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL