columnTestconstno test imports itconst columnTest: <A = void>(name: string, failing: (c: Context<"column">, args: A) => string) => GenericTest<A, "column">Makes a generic test of the level of a column.
SQL data quality, SQL-DQ (commons data 0052-sql-quality): data tests as typed values, an algebra of the data tests of dbt. A test is SQL that gives the rows that are wrong; it passes where there are none. A generic test is a value that is made once, with the type of its arguments and the level it is written at (a column or a model), and used any number of times; a singular test is SQL of one's own. The configuration of a use (severity, warnIf and errorIf thresholds, where, limit, failCalc, stored failures, tags, meta, name, enabled) is a typed record, and what a run finds is a sum of outcomes.
Pure: a test makes SQL for a dialect and runs nothing; run.ts runs it through a driver. It is a unit of its own because it is used by the project command, by models and by a person's own checks alike, and because nothing in it is about the shape of a schema.
columnTestconstno test imports itconst columnTest: <A = void>(name: string, failing: (c: Context<"column">, args: A) => string) => GenericTest<A, "column">Makes a generic test of the level of a column.
exactlyconstconst exactly: (n: number, config?: TestConfig) => TestConfigThe configuration of a test that expects a number of failing rows, exactly: it fails where the count is any other, and is never a warning. exactly(0) is the ordinary test; exactly(3) is the book's seeded test (three rows are wrong and the test says so), which fails both where one of them is missed and where a new one appears.
| Parameter | What it is |
|---|---|
n | the number of failing rows (or the value of failCalc) that is expected |
config | the rest of the configuration |
DqTesttypetype DqTest =
| { readonly kind: "generic"; readonly name: string; readonly test: string; readonly relation: Relation;… (401 characters)type DqTest =
| { readonly kind: "generic"; readonly name: string; readonly test: string; readonly relation: Relation; readonly column?: string; readonly args: unknown; readonly config: TestConfig; readonly failing: (d: Dialect) => string }
| { readonly kind: "singular"; readonly name: string; readonly relation?: Relation; readonly config: TestConfig; readonly failing: (d: Dialect) => string };A test that is placed: what it tests, and the SQL of the rows that are wrong.
GenericTestinterfaceno test imports itinterface GenericTest<A, L extends Level>A generic test: a name, a level, the type of its arguments and the SQL of the rows that are wrong.
| Member | Type | What it is |
|---|---|---|
kind | "generic" | |
name | string | |
level | L | |
failing | (c: Context<L>, args: A) => string |
judgefunctionfunction judge(failures: number, config: TestConfig): "fail" | "pass" | "warn"The status that a number of failures gives, as dbt determines it: with severity error, a number that meets errorIf is a failure and, below it, one that meets warnIf is a warning; with severity warn, a number that meets either threshold is a warning. Both thresholds are != 0 where they are not said.
Leveltypeno test imports ittype Level = "column" | "model";Where a generic test is written: on a column, or on a whole model.
meetsconstno test imports itconst meets: (n: number, t: Threshold) => booleanWhether a number meets a threshold.
modelTestconstno test imports itconst modelTest: <A = void>(name: string, failing: (c: Context<"model">, args: A) => string) => GenericTest<A, "model">Makes a generic test of the level of a model.
onfunctionfunction on(relation: string | Relation): OnRelationStarts the tests of a relation; a generic test of a column cannot be put on a model, nor a test of a model on a column: it does not compile.
OnRelationinterfaceno test imports itinterface OnRelationThe tests of one relation, written the way a project of dbt writes them: under a column, or under the model.
| Member | Type | What it is |
|---|---|---|
column | (name: string, ...uses: readonly Use<"column">[]) => readonly DqTest[] | Tests of a column. |
model | (...uses: readonly Use<"model">[]) => readonly DqTest[] | Tests of the model. |
Relationinterfaceno test imports itinterface RelationA table or a view by the name it has in the database.
| Member | Type | What it is |
|---|---|---|
name | string | |
schema? | string |
selectfunctionfunction select(tests: readonly DqTest[], s: Selection): readonly DqTest[]The tests that a selection picks: a test is picked when it meets every part the selection has (a tag that it has, a relation, a name, a kind) and is not picked by exclude.
Selectioninterfaceno test imports itinterface SelectionThe tests of a selection: by tag, relation, level or kind of test, by name, and what is left out.
| Member | Type | What it is |
|---|---|---|
tags? | readonly string[] | |
relations? | readonly string[] | |
tests? | readonly string[] | |
kind? | "generic" | "singular" | |
exclude? | Selection |
singularfunctionfunction singular(name: string, sql: string, config?: TestConfig, relation?: Relation | undefined): DqTestA singular test: SQL of one's own that gives the rows that are wrong.
TestConfiginterfaceno test imports itinterface TestConfigWhat a use of a test is told: dbt's configs of a data test.
| Member | Type | What it is |
|---|---|---|
severity? | "error" | "warn" | error where it is not said. |
warnIf? | Threshold | Where a test is a warning: != 0 where it is not said. |
errorIf? | Threshold | Where a test is a failure, for severity error: != 0 where it is not said. |
where? | string | A condition that the rows tested must meet, written in the dialect. |
limit? | number | The most failing rows that are looked at, and stored. |
failCalc? | string | The expression that is compared with the thresholds: count(*) where it is not said. |
storeFailures? | boolean | |
storeFailuresAs? | "table" | "view" | |
schema? | string | The schema the failures are stored in, and the name they are stored under (the name of the test where it is not said). |
alias? | string | |
tags? | readonly string[] | |
meta? | { readonly [key: string]: string | number | boolean; } | |
enabled? | boolean | false takes the test out of a run: it is reported as skipped. |
name? | string | The name of the test, where the one that is made from its parts is not wanted. |
testNamefunctionfunction testName(test: string, relation: Relation, column: string | undefined, args: unknown): stringThe name a test has where none is given: the test, the relation, the column and the arguments, as dbt makes it (accepted_values_orders_status__a__b).
Thresholdinterfaceno test imports itinterface ThresholdHow many failing rows (or the number failCalc gives) make a test warn or fail: { op: ">", n: 10 } is dbt's > 10.
| Member | Type | What it is |
|---|---|---|
op | "!=" | "<" | "<=" | "=" | ">" | ">=" | |
n | number |
usefunctionfunction use<A, L extends Level>(test: GenericTest<A, L>, ...rest: [A] extends [void] ? [args?: undefined, config?: TestConfig | undefined] : [args: A, config?: TestConfig | undefined]): Use<L>Uses a generic test: its arguments (none to give where it takes none) and, last, its configuration.
use(acceptedValues, { values: ["a", "b"] }, { severity: "warn", where: "created > '2026-01-01'" });
use(notNull);Useinterfaceno test imports itinterface Use<L extends Level>A use of a generic test, with its arguments and its configuration, still without a place.
| Member | Type | What it is |
|---|---|---|
test | GenericTest<never, L> | |
args | unknown | |
config | TestConfig |