Migrate from dbt
starlake dbt import converts a dbt project into native Starlake YAML and SQL, once. It reads the project as dbt resolved it, from target/manifest.json, expands every macro, and writes transform tasks, load tables, external tables, expectations and doc blocks into the current Starlake project. After the import, the project needs nothing of dbt.
Before you start
In the dbt project, build the manifest. No warehouse connection is needed:
dbt deps
dbt parse --target prod
The schemas and table names of the import are the ones dbt resolved at dbt parse, with the target of that command. Parse with the target whose names you want in Starlake: a dev target bakes its dbt_<user>_... schemas into every domain and every ref(). The --target of the import only sets target.* and the DuckDB connection; it does not change the names.
The imported tasks write the same schema.table as dbt. The DuckDB connection made from --profiles points at dbt's own database file, and a --connection to production means that the first starlake transform replaces the tables dbt built. Run the import and the first transforms on a copy of the database, or on a dev database.
The import renders the project's macros and the macros of its packages, as dbt compile does: only import a dbt project that you would compile.
Then, in an existing Starlake project (starlake bootstrap creates one), with SL_ROOT pointing to it:
starlake dbt import --manifest ../my_dbt_project/target/manifest.json \
--profiles ~/.dbt/profiles.yml --target dev
| Option | Meaning |
|---|---|
--manifest | dbt's target/manifest.json (manifest v10 to v12, written by dbt 1.6 and later). The dbt project is the parent of target/. |
--profiles, --target | the dbt target: target.name, target.schema and target.database render with its values, and a DuckDB target with a file becomes a Starlake connection in application.sl.yml. Without --target, the target is the one of the profile, else dev. Values such as "{{ env_var('DBT_DUCKDB_PATH') }}" are rendered with env_var() and var(), as dbt does; when one of them cannot be rendered (an env var that is not set and has no default), no connection is written and the report names the field. |
--connection | an existing Starlake connection to run the imported objects on; the command fails when the project has no connection of that name. Needed for every target that does not become a connection: any warehouse but DuckDB, and a DuckDB target without a file. |
--vars | as dbt's --vars, a YAML or JSON map, over the vars of dbt_project.yml, whose env_var() and var() are rendered too. |
--introspect | answer the macros that read the warehouse at import (run_query, statement / load_result, load_relation, adapter.get_relation, adapter.get_columns_in_relation, adapter.get_missing_columns) on the import's connection: --connection, or the DuckDB target of --profiles. It works on JDBC connections and BigQuery. Without a connection the command exits with 1. See Introspect the warehouse. |
--introspect-max-rows | with --introspect, the most rows a query may return (default 10000, must be positive). A model whose query returns more is skipped. |
--force | overwrite the files that the import writes. Without it, the import writes nothing when one of them exists, and lists them. Nothing is ever deleted. |
The command exits with 0 when the import ran, even if some objects were skipped, and with 1 on a usage error, a manifest it cannot read, existing files without --force, or, with --introspect, no connection, a connection that cannot open, or a connection that is neither JDBC nor BigQuery. The command reference lists every option.
Before loading, check the connection the imported objects run on: the one the import added or the one given with --connection, else the default connectionRef of application.sl.yml:
starlake settings --test-connection <connection name>
Then load the seeds and run the transforms. The Notes section at the top of dbt-import-report.md gives the task list to pass to --name; copy it from there (the names below are an example):
starlake stage
starlake load
starlake transform --name staging.stg_orders,marts.orders
What the import writes
Names are dbt's, after generate_schema_name and aliases: the domain is the dbt schema, the table the alias (the identifier of a source). ref() and source() render as domain.table, so lineage, starlake impact and DAG generation work unchanged. When the database of the node is not the default database of the project (the most frequent one of its models and seeds), they render as database.schema.table.
An object whose schema, alias or file name cannot be a folder or file name, such as ../x or a:b, is skipped with its reason, and the import never writes outside the metadata and datasets folders of the project. When two objects map to the same file, such as the same schema and alias in two databases, the first one is imported and the next ones are skipped, with a reason that names it.
Models: transform tasks
Each model becomes metadata/transform/<schema>/<alias>.sl.yml and <alias>.sql.
| dbt | Starlake |
|---|---|
table | OVERWRITE |
view | OVERWRITE with sink.materializedView: VIEW |
ephemeral | the same as view: one more object in the warehouse |
incremental append, or merge without unique_key | APPEND |
incremental merge with unique_key | UPSERT_BY_KEY on that key |
incremental delete+insert with unique_key | DELETE_THEN_INSERT on that key |
incremental insert_overwrite with partition_by | OVERWRITE_BY_PARTITION |
| incremental without a strategy | append without a unique_key; with one, merge on BigQuery, Snowflake, Databricks and Spark, delete+insert elsewhere |
pre_hook, post_hook | presql, postsql |
partition_by, cluster_by | sink.partition, sink.clustering |
tags, descriptions, column data_type | tags, comments, attribute types |
Microbatch and other incremental strategies, Python models and custom materializations are skipped, with their reason. on_schema_change, full_refresh: false, grants and contract have no equivalent: the report lists them.
Incremental models
The import renders each incremental model twice, with is_incremental() false and true, and keeps what differs as sl_incremental blocks:
select event_id, customer_id, event_type, occurred_at
from staging.stg_events
{% if sl_incremental %}
where occurred_at > (select max(occurred_at) from marts.events_append)
{% endif %}
sl_incremental is true when the table exists and the run is not --truncate, as is_incremental() is in dbt.
Reserved CTE names
A CTE named like a word that Starlake's SQL parser reserves (final, window, output, pivot, unpivot, lateral, natural) is renamed sl_<name> at import, with or without --introspect, and the model gets a note. The final CTE of the dbt style guide is the common case. If the SQL still cannot be read, it is kept as it is and the model gets a note.
Seeds, sources, tests, docs
- A seed becomes a load table,
metadata/load/<schema>/<alias>.sl.yml, typed by Starlake's schema inference and thecolumn_typesof the seed, written inOVERWRITE. Its CSV is copied to the incoming area of its domain, wherestarlake stagefinds it. A CSV outside the dbt project (dbt_packagesincluded) is not copied: the seed is skipped. - A domain file,
metadata/load/<schema>/_config.sl.ymlormetadata/external/<schema>/_config.sl.yml, that exists is kept as it is, never overwritten. The seed tables of a kept load domain then carry their own metadata, so that the CSV is read as the import intends whatever the kept file says (directory, format, header, separator, encoding, quote, escape, multiline, array, write strategy, sink), and their CSVs go to the pending area of the domain, wherestarlake loadreads them. The other settings of the kept file (nullValue,emptyIsNull,options,ack,loader,schedule,dagRef,freshness,archive) still apply to the seed tables; the report names the kept file and these settings. - A source becomes an external table,
metadata/external/<schema>/<identifier>.sl.yml, with its columns and its freshness ({count: 12, period: hour}is12 hours).starlake freshnesschecks load tables and tasks, not external tables, andloaded_at_fieldis not used: the report says so. A source that is the table of a seed is declared by the seed's load table. - A test becomes an expectation of the task or table it tests, which passes when it returns 0.
not_null,unique,accepted_valuesandrelationshipscall the macrosdbt_not_null,dbt_unique,dbt_accepted_valuesanddbt_relationshipsofmetadata/expectations/dbt.j2; any other test, from a package or a.sqlfile, gets a macro of its own there, with its SQL.severity: warnisfailOnError: false, andwherefilters the tested rows. A test that reads a table built after the tested one, such as arelationshipsto a downstream model, runs after that table, and the report says so. The tests of a source that is not a seed are skipped: external tables run no expectations. {% docs %}blocks go tometadata/docs/dbt/<package>/<name>.md, and descriptions refer to them with{{ doc('name') }}.
Exposures, metrics, semantic models, saved queries, unit tests, analyses, snapshots and on-run-start / on-run-end hooks are only listed in the report.
Introspect the warehouse
Some macros ask the warehouse a question while they render: run_query, statement and load_result, load_relation, adapter.get_relation, adapter.get_columns_in_relation, adapter.get_missing_columns. Without --introspect, a model that uses one is skipped. With it, the import runs the question on its connection and writes the answer into the SQL: a column list, a list of values, a date range.
starlake dbt import --manifest ../my_dbt_project/target/manifest.json \
--profiles ~/.dbt/profiles.yml --target dev --introspect
The connection must hold the dbt tables the macros read, so run dbt build or starlake load first. If the connection cannot be opened, the import stops with exit 1 before it writes anything. A connection of another type, a file system connection for example, is refused. Without --connection, the DuckDB file of the --profiles target is opened read-only, and it must exist: when it does not, the import stops with exit 1 and names the file.
- Only read-only statements run:
SELECT,WITH,SHOW,DESCRIBEandEXPLAINof a read. A statement that writes, or that the SQL parser cannot read, skips its model withstatement is not read-only: .... - The check is on the kind of statement, not on the functions that a
SELECTcalls: aSELECTthat calls a function with side effects, such asnextvalorpg_terminate_backend, runs. Introspect with a read-only user or role. - The adapter methods that write, such as
adapter.drop_relation,adapter.create_schemaoradapter.rename_relation, never run: their model is skipped withwrites to the warehouse at import (adapter.<method>). - A query times out after the
queryTimeoutoption of the JDBC connection, in seconds; without it, and on BigQuery, aftershortJobTimeoutMs(3 minutes by default). - A query that returns more than
--introspect-max-rowsrows (10000 by default) skips its model. The option needs--introspect. - When the warehouse does not have a relation that a macro reads (its columns come back empty, or
adapter.get_relationanswers none), the SQL is written from that answer and the model gets a note that names the relation: check that the table was built before the import. A model that passes something other than a relation toadapter.get_columns_in_relation, such as a string or none, is skipped. - The answers are a snapshot of the warehouse at import time. To refresh them, import again. When a macro orders values with ties (
dbt_utils.get_column_valuesorders by count by default), the order that is written can differ between two imports. graphis answered from the manifest, with or without--introspect.
The jaffle-shop project imports with its 19 tables, metricflow_time_spine included.
Read the report
The import prints a summary and writes dbt-import-report.md at the root of the project:
- Notes: the connection that was added, the connection of the introspection (
introspection on connection <name>), the hooks that were not imported, and the next commands. - Converted, and Converted with notes: what the import could not carry over exactly, such as a setting with no equivalent, a test that runs on another task, or, with
--introspect, a relation that the warehouse did not have. - Skipped, with the reason. A model whose macros need the warehouse at import (
run_query,statement,adapter.get_columns_in_relation...) is skipped without--introspect; with it, a model that runs a statement or an adapter method that writes is skipped. A model whosevar()orenv_var()has no value, that reads aDBT_ENV_SECRETenv var (dbt allows them only inprofiles.ymlandpackages.yml), or that callsexceptions.raise_compiler_erroris skipped too, and so is a test of a skipped model. - Not imported: the objects disabled with
enabled: false. - Downstream of skipped objects: every task that depends on a skipped or disabled object, directly or through other tasks (views and ephemeral models included) or through the source of a skipped seed, with the skipped objects it reaches. They are converted, but they cannot run until you write the missing tables, and the task list of the Notes leaves them out.
- Warehouse answers, with
--introspect: each statement run or relation read, with its answer (a number of rows or columns,foundormissing) and the tasks that used it. - Baked vars and Baked env vars: the values written into the SQL. Change them in the SQL, or replace them with Starlake variables.
- Reported only: the dbt objects that have no Starlake equivalent.
Limitations
- Macros are expanded, not kept: the SQL of each task is plain SQL, except its
sl_incrementalblocks. - The values of
run_started_atandmodules.datetimeare those of the import; the report flags the tasks that use them. - A string literal that holds
{{,{%or{#is split withCONCATso that Starlake's Jinja leaves it alone. - Without
--connection, only a DuckDB target with a file becomes a connection; the report says what to do for another target.application.sl.ymlis rewritten without its comments when a connection is added. - With
--introspect, the values that the warehouse returned are in the SQL: they are those of the import. Import again to refresh them. graphis supported, from the manifest.- Snapshots, microbatch models and
SCD2with check columns come in later releases.