Skip to content

CLI commands

sqlbabel census

Which files convert, and a diagnostic for each that doesn't.

sqlbabel census reads a folder of SQL files, converts each one, and prints a diagnostic for every file that doesn’t convert, then a short summary. Its exit status tells CI whether everything converts.

sqlbabel census [OPTIONS] <PATHS>...
sqlbabel census target/compiled/my_project/models --no-config
sqlbabel census target/compiled --json --no-config

Each .sql file is one query, or one model compiled by SQLBuild or dbt; SQLBuild’s reference calls are recognised. A directory is searched for .sql files. The tables they read come from the project you run it in. Compiled models name relations as database.schema.table; see Projects for how they resolve.

$ sqlbabel census models --no-config
error[SBL0004]: SQLBabel doesn't know this name
--> models/marts/customer_sounds.sql:4:6
|
4 | FROM __ref("stg_customers")
| ^^^^^^^^^^^^^^^^^^^^^^ relation `__SQLBABEL_RELATION__STG_CUSTOMERS` has no known columns
|
= help: declare the relation and its columns in a source file of the project (`sources/*.yml`)
error[SBL0002]: SQLBabel can't convert WEEKISO yet
--> models/staging/stg_orders.sql:1:31
|
1 | SELECT order_id, customer_id, WEEKISO(ordered_at) AS order_week FROM orders
| ^^^^^^^^^^^^^^^^^^^ no rule converts WEEKISO
Converted 1 of 3 files (33%)
Blocked: 2 files, 2 causes (SBL0002 WEEKISO, SBL0004 STG_CUSTOMERS)
sqlbabel census: done, 3 files in … s

Each diagnostic has the same code, message and help that convert gives for that file; see the diagnostic reference for each code’s fix. The summary names at most five causes, then counts the rest. A cause names the construct, divergence or unknown relation behind it.

By default census converts each file on its own. A file reading another model converts only when the project declares that model’s columns. When the model it reads doesn’t convert either, its diagnostic carries a note naming that model, and it isn’t counted as a separate cause:

error[SBL0004]: SQLBabel doesn't know this name
--> models/marts/customer_report.sql:1:58
|
1 | SELECT customer_id, UPPER(name_sound) AS name_sound FROM __ref("customer_sounds")
| ^^^^^^^^^^^^^^^^^^^^^^^^ relation `__SQLBABEL_RELATION__CUSTOMER_SOUNDS` has no known columns
|
= note: reads `customer_sounds`, which doesn't convert
= help: declare the relation and its columns in a source file of the project (`sources/*.yml`)
…
Converted 1 of 4 files (25%)
Blocked: 3 files, 2 causes (SBL0002 WEEKISO, SBL0004 STG_CUSTOMERS)

--chain-models converts in model order instead: each converted file types the relation its file name references, read by any qualifier as dbt writes it, and the files reading it convert against those columns. With --chain-models, census also warns about each file that converts while reading a model that doesn’t, which happens when the project already types that model:

…
warning: models/marts/customer_report.sql converts, but reads customer_sounds, which doesn't
--> models/marts/customer_report.sql
Converted 2 of 4 files (50%)
Blocked: 2 files, 2 causes (SBL0002 SOUNDEX, SBL0002 WEEKISO)
Converts with a blocked upstream model: 1

--json prints the same result as one object:

Field Meaning
ok Whether every file converts.
files, converted Files read, and files that convert.
blocked Each blocked file’s path and diagnostics, each diagnostic as in JSON output.
causes Each cause’s code, cause and the files it blocks, most first.
upstream With --chain-models, each file that converts but reads a blocked model: its path, and the blocked models’ files in reads.

--detailed and --anonymous print a coverage report instead of diagnostics: construct counts, refusals by category and construct, and what blocks files through the model graph.

  • --detailed names files, models and relations, and lists the slowest files.
  • --anonymous holds counts and construct names only, never SQL text or file, model or relation names, so you can share it. With both flags, the report stays anonymous.
$ sqlbabel census models --no-config --anonymous
Census of 3 snowflake SQL files
parsed 3 (3 statements), unparsed 0, empty 0
distinct constructs 6 (2 fn, 4 node)
files refused: missing rule 1, outside type conditions 0, unresolved name 1, not expressible 0, parse fidelity 0, conversion budget 0, known difference not allowed 0
convertible: strict 1 (every model upstream converts too), unit-testable 1 (the file's own SQL converts; 0 with an upstream model refused or not scanned)
with no named assumption: strict 1, unit-testable 1 (relying on one: none)
Refusals by category and construct (top 50)
1 missing rule: fn:WEEKISO
1 unresolved name: statement
…
sqlbabel census: done, 3 files in … s
Count Meaning
unit-testable The file’s own SQL converts.
strict It converts and so does every model upstream of it.
with no named assumption The same counts, leaving out files that rely on an assumption such as session_timezone_utc.

A file reading a refused model is labelled upstream_refused:<model>, and one reading a model the scan holds no file for, upstream_missing:<relation>.

--assume-supported takes construct keys or rule.<id>s and reports how many files would then convert, what blocks the rest next, and a plan of the constructs each step should support together. Every such figure is an upper bound: it counts only the refusals collected, and supporting a construct may uncover others.

Option Meaning
--project <folder> The project declaring the tables the files read. Default the current folder.
--chain-models Type each converted file as the relation its name references, and convert its readers against it.
--cursor-type timestamp|integer Replace SQLBuild’s cursor intrinsics with a bound as SQLBuild renders one.
--dialect <dialect> The dialect the SQL is written in. Default snowflake.
--overrides, --verified-override As for convert.
--format text|json, --json Print the result as text or JSON.
--detailed Print the coverage report, with names and the slowest files, instead of diagnostics.
--anonymous Print the coverage report with counts and construct names only. Wins over --detailed.
--assume-supported <keys> With --detailed or --anonymous: construct keys or rule.<id>s to treat as supported, comma-separated. Needs --chain-models.
--limit <n> With --detailed or --anonymous: constructs listed in the text report. Default 50.

census also takes the policy flags. It takes no session parameters and converts as for a Snowflake session in UTC. See Sessions.

Code Meaning
0 Every file converts.
1 At least one file is blocked.
2 Census can’t run: bad arguments, an unreadable path, no SQL files, or a project it can’t load.

The coverage report exits the same way.