Experimental. Counts the rows returned by each view in a schema set aside for data checks. The convention: a check is a view that returns the rows breaking a rule, the view's name is the rule's id, and its comment is the rule's label. Checks written this way live in the DuckLake catalog, so they are versioned with the data and every client of the lake can run them. The interface may change while the convention settles.
Value
A data frame with one row per check, ordered by name: check
(the view name), label (the view's comment, NA without one), and
n_fail (the number of rows the view returns). Zero rows when the
schema holds no views.
Details
Write a check with create_check(), which takes the rule as it is said
and keeps the rows that break it, or with create_view() from a pipeline
that returns the failing rows itself, labelled with
set_table_comment(). A row where the rule is NA passes, so a missing
value needs a rule of its own. Read the table by its schema-qualified
name, get_ducklake_table("main.cars"): the view then binds whichever
database is current, for this function's ducklake_name and for other
clients of the lake.
Every view in the schema counts as a check, so keep other views elsewhere. A view that summarizes, returning a row of totals, reports a failure every time. A check whose view no longer binds, after a column rename for instance, is an error and not a pass; DuckDB's message quotes the line naming the view.
Inside with_transaction() the counts include the transaction's pending
writes, so a load can be checked before it commits: stop() when a check
fails and the transaction rolls back. On a lake attached with
snapshot_version or snapshot_time, the checks and the data are both
read as of that snapshot.
See also
create_check() to write a check, with_transaction() to gate
a load on the result, and vignette("data-checks").
Examples
lake_dir <- tempfile("checks_lake_")
dir.create(lake_dir)
attach_ducklake("checks_lake", lake_path = lake_dir)
create_table(mtcars, "cars")
get_ducklake_table("main.cars") |>
create_check("cyl_known", cyl %in% c(4, 6, 8), label = "cyl is 4, 6, or 8")
#> Created check "cyl_known" in "checks": cyl is 4, 6, or 8
run_checks()
#> check label n_fail
#> 1 cyl_known cyl is 4, 6, or 8 0
detach_ducklake("checks_lake", shutdown = TRUE)
unlink(lake_dir, recursive = TRUE)
