vgi-dbt

module
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Nov 16, 2026 License: 0BSD

README

Vector Gateway Interface (VGI)

Query dbt Artifacts and dbt Cloud as SQL in DuckDB

vgi-dbt · a Query.Farm VGI worker

CI

dbt writes everything it knows about a project into four JSON files: manifest.json, run_results.json, catalog.json and sources.json. In DuckDB, read_json('manifest.json') returns one row holding a project-specific STRUCT with one field per node. That type is slow to infer, changes between projects and dbt releases, and is built in full before the first row comes back.

This worker streams the same files into flat tables whose columns stay the same across projects and across manifest schema versions v7 to v12 (dbt 1.3 to 1.12). It skips unselected raw_code and compiled_code without decoding them. It also reads dbt Cloud (Admin API v2/v3 and the Discovery API), and exposes the unified.runs / unified.task_runs shape that the other orchestrator workers share.

The artifact half runs offline and needs no credentials, no network and no dbt install.

Quick start

INSTALL vgi FROM community;     -- Haybarn 2.0; on DuckDB 2.0 use the query_farm repository
LOAD vgi;
ATTACH 'dbt' (TYPE vgi, LOCATION 'github-auto://Query-farm/vgi-dbt@v0.1.1');
Other ways to run it
  • DuckDB 2.0: SET allow_extension_repositories = 'allowed'; CREATE EXTENSION REPOSITORY IF NOT EXISTS query_farm WITH PREFIX 'https://duckdb-extensions.query.farm'; INSTALL vgi FROM query_farm; LOAD vgi FROM query_farm; then attach as above.
  • Docker (HTTP): docker run -p 8000:8000 ghcr.io/query-farm/vgi-dbt:0.1.1, then ATTACH 'dbt' (TYPE vgi, LOCATION 'http://localhost:8000').
  • From source: make build (Go 1.26+, a C toolchain for cgo), then ATTACH 'dbt' (TYPE vgi, LOCATION '/abs/path/to/bin/vgi-dbt-worker').

v0.1.0 is not published yet. Until it is, build from source.

First query: triage, bind, query

Start with artifact_info. It reports whether your manifest version is supported before you run anything else. Then bind each artifact once as a view and join the views. Every function takes the path explicitly, so you can compare two manifests (main and a PR) in one session.

SELECT artifact_type, schema_version, dbt_version, node_count, support_status
FROM dbt.main.artifact_info('target/*.json');

CREATE VIEW nodes      AS SELECT * FROM dbt.main.nodes('target/manifest.json');
CREATE VIEW depends_on AS SELECT * FROM dbt.main.depends_on('target/manifest.json');

SELECT materialized, count(*) FROM nodes WHERE resource_type = 'model' GROUP BY ALL;

The worker also bundles real artifacts from a small jaffle_shop project, generated by dbt-core 1.3 through 1.12. You can try it with no project of your own: dbt.main.nodes('sample://jaffle_shop/v12/manifest.json'). The samples cover sample://jaffle_shop/{v7,v8,v9,v10,v11,v12}/{manifest,run_results,catalog,sources}.json, and globs work.

What's inside

main: artifact tables (offline)

The artifact argument can be any of these:

  • a local path, or a glob with *, ? and ** (one partition per file);
  • an https:// URL;
  • sample://... (the bundled samples);
  • dbt-cloud://runs/<run_id>/<file>.json, or dbt-cloud://jobs/<job_id>/<file>.json for the job's latest run. Add ?step=N for a single step's artifacts.
Function Reads One row per
artifact_info(path) any artifact file: type, schema version, dbt version, node count, size, support_status, warning
nodes(manifest) manifest node: ids, relation, materialized, tags, meta/config (JSON), raw_code, compiled_code, fqn, checksum, group, access, contract, ...
node_columns(manifest) manifest declared (YAML/contract) column
depends_on(manifest, kind := 'nodes') manifest DAG edge (kind := 'macros' for macro edges)
sources(manifest) manifest declared source table
exposures / metrics / semantic_models / groups / macros (manifest) manifest object of that kind
run_results(path) run_results node result: status, timing, rows affected, failures, message
run_timings(path) run_results compile / execute phase
catalog_columns(path) catalog warehouse-observed column
source_freshness(path) sources freshness result
descendants / ancestors(unique_id, manifest := ..., max_depth := 64, include_self := false) manifest reachable node, with depth and path (per row, LATERAL-friendly)
parse_selector(selector) none selector atom: kind, value, supported, reason
schema_versions (table) none supported artifact schema version

Scalars: parse_unique_id(id) returns STRUCT(resource_type, package, name, version). selector_match(unique_id, fqn, tags, materialized, selector), manifest_version(path) and normalize_relation(db, schema, identifier, quoting) complete the set.

Selectors are a strict subset. The supported terms are tag:, path:, fqn:, package:, resource_type:, config.materialized: and bare names or globs. A space means union and a comma means intersection. Everything else is a bind error that names the term: graph operators (+, n+, @), state:, result:, source_status:, other methods and --exclude. You never get a silent false. parse_selector shows which term was rejected and what to use instead. For --exclude, write NOT selector_match(...). For graph operators, use descendants / ancestors. path: is matched against fqn, which assumes the conventional models/ and seeds/ directories.

There is deliberately no checksum_changed. To compare two manifests, use a.checksum IS DISTINCT FROM b.checksum.

cloud: dbt Cloud (read-only)
CREATE SECRET (TYPE dbt_cloud, TOKEN 'dbtc_...', ACCOUNT_ID '12345');
-- Other hosts: BASE_URL 'https://emea.dbt.com' | 'https://au.dbt.com' | 'https://ab123.us1.dbt.com'
-- Optional: DISCOVERY_URL (derived from BASE_URL), ENVIRONMENT_ID (default for Discovery functions)
Object API Notes
accounts, projects, environments, jobs (tables) Admin v2 / v3 environments is how you find environment_id / project_id
runs(cursor := '') Admin v2 newest first; incremental cursor = a run id
run_steps(run_id) Admin v2 steps with status, timing and logs
run_artifacts(run_id) Admin v2 artifact_url feeds the main tables directly
models / tests / sources (environment_id := N) Discovery (GraphQL) applied state with the latest execution and freshness
SELECT count(*) FROM dbt.main.nodes('dbt-cloud://runs/70403103/manifest.json');
SELECT * FROM dbt.cloud.runs() WHERE job_id = 42 AND status = 'Error' AND created_at >= TIMESTAMPTZ '2026-10-01';

The token is sent as Authorization: Token ... to the Admin API and as a Bearer token to the Discovery API. It is never kept in scan state and never logged.

unified: the cross-orchestrator shape

unified.runs(path := '') and unified.task_runs(path := '', run_id := 0) use exactly the columns the airflow, dagster, prefect, temporal, databricks and github workers use. status is one of queued, running, success, failed, cancelled or skipped, and raw_status keeps dbt's own value. The arguments pick the source:

  • With a run_results.json path or glob, each file is one run (orchestrator = 'dbt') and each node result is a task.
  • Without a path, the account's dbt Cloud runs are read ('dbt_cloud'). task_runs() then returns their steps, and task_runs(run_id := N) returns the node results of that run.
SELECT * FROM dbt.unified.runs(path := 'archive/**/run_results.json')
UNION ALL SELECT * FROM dbt.unified.runs()
UNION ALL SELECT * FROM airflow.unified.runs;

What pushes down

Where Filter / projection Sent as
manifest tables any projection unselected JSON fields are skipped without decoding (raw_code, compiled_code, macro_sql, ...)
nodes, sources, macros resource_type, package_name (= / IN) node skipped from its unique_id before it is read
cloud.runs job_id, environment_id, project_id (=) job_definition_id=, environment_id=, project_id=
cloud.runs status (= / IN) status= / status__in=[..]
cloud.runs created_at range created_at__range=[lo,hi]
cloud.environments, cloud.jobs project_id, environment_id (=) query parameters
cloud.models / tests / sources unique_id (= / IN) GraphQL filter: {uniqueIds: [...]}
unified.runs() (dbt Cloud) status, queued_at range status__in, created_at__range

DuckDB does not re-check rows after it pushes a filter, so the worker applies every pushed filter exactly. Comparisons, IN, IS [NOT] NULL and AND/OR are evaluated in Go. Rarer shapes fall back to the SDK's embedded DuckDB evaluator, which is why the binary uses cgo. Pagination cursors (byte offsets into artifact files, API offsets, GraphQL cursors) live in serializable scan state, so long scans survive the HTTP transport. 429 and 5xx responses are retried with backoff that honours Retry-After.

Performance

These figures come from a synthetic 330 MB manifest with 5,000 models, each with 30 KB of raw_code and 30 KB of compiled_code (scripts/gen-synthetic-manifest.py). The worker was served over HTTP on an Apple-silicon Mac. Times are as measured in one run.

Query Time Worker peak RSS
SELECT unique_id, name FROM nodes(...) LIMIT 1 (first row) 0.07 s
SELECT count(*) FROM nodes(...) 0.52 s 53 MB
sum(length(compiled_code)) (decodes every code string) 2.7 s 332 MB (session peak)
descendants(...) on the 5,000-node DAG (cold) 1.9 s
DuckDB SELECT count(*) FROM read_json(manifest) 10.6 s DuckDB 1.5 GB
DuckDB json_keys(json->'nodes') via read_json_objects out of memory at memory_limit='4GB'

Version support and dbt Fusion

manifest.json v7 to v12 are supported. The bundled samples come from real dbt-core runs of 1.3, 1.4, 1.5, 1.6, 1.7 and 1.12. A newer version the worker has not seen is best_effort: it parses and artifact_info returns a warning row, but it never crashes. Anything below v7 is unsupported and still parsed best-effort: raw_sql/compiled_sql map to raw_code/compiled_code.

The commitment covers the current dbt minor release plus the previous 24 months of minor releases. dbt.main.schema_versions is that policy as a table. For the other artifacts, run_results v4 to v6, catalog v1 and sources v3 are supported.

Fusion. The dbt Fusion engine is the next big change to artifacts. The worker's position: artifact_info turns incompatibility into a row, not a crash, and the support window above is explicit. dbt-core 1.12.7 still writes manifest v12, which the v12 sample verifies. Archived artifacts never change, so archaeology over existing run_results is unaffected either way. If Fusion ships a v12-compatible manifest, the normalization layer extends to it. If it ships a different artifact set, that is a new version in schema_versions, not a silent misparse.

Ten SQL queries to audit your dbt project

audit/audit.sql holds 15 queries that run as written against the bundled samples. Edit its preamble to point at your target/. Ten of them:

-- views: nodes, depends_on, decl_cols, cat_cols, results, freshness, src (see the preamble)
-- 1. Models with no tests
SELECT m.unique_id FROM nodes m WHERE m.resource_type = 'model' AND m.unique_id NOT IN (
  SELECT d.depends_on_id FROM depends_on d JOIN nodes t ON t.unique_id = d.unique_id WHERE t.resource_type = 'test');
-- 2. Test coverage by layer
SELECT fqn[2] AS layer, count(*) FROM nodes WHERE resource_type = 'model' GROUP BY layer;
-- 3. Undocumented models (no description, no documented column)
SELECT unique_id FROM nodes m WHERE resource_type = 'model' AND description = ''
  AND NOT EXISTS (SELECT 1 FROM decl_cols c WHERE c.unique_id = m.unique_id AND c.description <> '');
-- 4. Orphan models nothing depends on
SELECT unique_id FROM nodes WHERE resource_type = 'model' AND unique_id NOT IN (SELECT depends_on_id FROM depends_on);
-- 5. Slowest models over an archive of runs (p50 / p95)
SELECT unique_id, median(execution_time), quantile_cont(execution_time, 0.95) FROM results
WHERE status = 'success' GROUP BY 1 ORDER BY 3 DESC LIMIT 10;
-- 6. Flakiest tests
SELECT unique_id, count(*) FILTER (WHERE status IN ('fail', 'error')) AS failures FROM results
WHERE unique_id LIKE 'test.%' GROUP BY 1 HAVING failures > 0 ORDER BY failures DESC;
-- 7. Contract drift: declared vs. warehouse types
SELECT d.unique_id, d.name, d.data_type, c.column_type FROM decl_cols d JOIN cat_cols c
  ON c.unique_id = d.unique_id AND lower(c.column_name) = lower(d.name)
WHERE d.data_type IS NOT NULL AND lower(d.data_type) <> lower(c.column_type);
-- 8. Stale or unchecked sources
SELECT s.unique_id, coalesce(f.status, 'not checked') FROM src s LEFT JOIN freshness f USING (unique_id)
WHERE f.status IS DISTINCT FROM 'pass';
-- 9. Blast radius of each staging model
SELECT n.unique_id, count(*) FROM nodes n, dbt.main.descendants(n.unique_id, manifest := 'target/manifest.json') d
WHERE dbt.main.selector_match(n.unique_id, n.fqn, n.tags, n.materialized, 'tag:staging') GROUP BY 1;
-- 10. DAG drift between main and this PR
SELECT * FROM dbt.main.depends_on('target/manifest.json') EXCEPT SELECT * FROM dbt.main.depends_on('main/manifest.json');

How it is tested

make check runs gofmt, go vet and golangci-lint, the Go unit and fuzz-seed tests, and the SQLLogicTests through the real vgi extension (Haybarn 2.0.0rc11) over stdio, launch: (unix socket) and HTTP. It finishes with vgi-lint at fail_on = "info".

  • Artifacts: real dbt-core + dbt-duckdb runs of test/dbt_project, made by scripts/gen-dbt-artifacts.sh in a throwaway uv environment, for dbt 1.3.7, 1.4.9, 1.5.11, 1.6.18, 1.7.19 and 1.12.7 (manifest v7 to v12). The runs include a failing relationship test, a warning test and a stale source. Hand-made edge cases live in test/fixtures/synthetic: a future v13 manifest, a v5 manifest, a truncated file and a non-dbt file.
  • dbt Cloud: test/mock_api/server.py replays JSON fixtures through a stdlib HTTP server that follows the documented Admin API v2/v3 and Discovery API request and response shapes. It implements the documented filters, caps every page at 3 items so pagination always runs, and answers each new URL with 429 once. It also records every request, so the SQL tests assert which pushdown parameters reached the API. The fixtures were built by hand from the documented API shapes, not recorded from a live account.
  • Fuzzing: go test ./internal/dbt -fuzz FuzzArtifactParsers runs every parser under depth and size limits, and -fuzz FuzzSelector runs the selector parser.

Known limitations

  • TIMESTAMPTZ filters and a non-UTC TimeZone: in a session with ICU loaded and TimeZone set to anything but UTC, a pushed-down filter on a TIMESTAMPTZ column fails with "comparison operands have incompatible types". This happens in vgi-go 0.42.0, which compares the column's timestamp[us, UTC] with the literal's session-zone type, before the worker sees the filter. The workaround is SET TimeZone = 'UTC'.
  • s3:// and gs:// paths are not read directly. Use a presigned https:// URL or a local copy.
  • Model-version and semantic-layer fields are exposed as JSON where their shape is still changing (entities, dimensions, measures).

Support

Open an issue on this repository. For VGI itself, see query.farm.

Authorship & License

Copyright 2026 Query Farm LLC - https://query.farm

Released under the BSD Zero Clause License (0BSD). No dbt-core code is linked. The artifact schemas published at schemas.getdbt.com were read as documentation and re-implemented.

Directories

Path Synopsis
cmd
vgi-dbt-worker command
Command vgi-dbt-worker serves the dbt catalog to DuckDB.
Command vgi-dbt-worker serves the dbt catalog to DuckDB.
Command recipes runs one recipe as a worker: recipes <recipe> [worker flags].
Command recipes runs one recipe as a worker: recipes <recipe> [worker flags].
internal
dbt
Package dbt exposes dbt artifacts (manifest.json, run_results.json, catalog.json, sources.json) and dbt Cloud as SQL.
Package dbt exposes dbt artifacts (manifest.json, run_results.json, catalog.json, sources.json) and dbt Cloud as SQL.
serve
Package serve is the command-line front end shared by the worker and the recipes binary: it parses the transport and logging flags and runs a *vgi.Worker on the transport they select.
Package serve is the command-line front end shared by the worker and the recipes binary: it parses the transport and logging flags and runs a *vgi.Worker on the transport they select.

Jump to

Keyboard shortcuts

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