dbt Renderer¶
Compiles dbt models via subprocess (dbt compile), then parses the compiled SQL with SqlParser.
DbtRenderer
¶
DbtRenderer(sql_parser=None)
Compiles dbt models via dbt compile and parses the resulting SQL.
Shells out to dbt (via uv run or a custom command) in the project's
own virtualenv, then reads compiled SQL from target/compiled/ and
feeds each model through SqlParser. dbt is not a Python dependency
of the indexer -- it uses whatever version the project has installed.
Initialise the renderer.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sql_parser
|
SqlParser | None
|
|
None
|
Source code in src/sqlprism/languages/dbt.py
87 88 89 90 91 92 93 94 | |
render_project
¶
render_project(
project_path,
profiles_dir=None,
env_file=None,
target=None,
dbt_command="uv run dbt",
venv_dir=None,
dialect=None,
schema_catalog=None,
)
Compile all dbt models and parse the resulting SQL.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
project_path
|
str | Path
|
Path to dbt project dir (containing dbt_project.yml) |
required |
profiles_dir
|
str | Path | None
|
Path to directory containing profiles.yml (defaults to project_path) |
None
|
env_file
|
str | Path | None
|
Optional .env file to source before running dbt compile |
None
|
target
|
str | None
|
dbt target name (default: whatever profiles.yml specifies) |
None
|
dbt_command
|
str
|
Command to invoke dbt (default: "uv run dbt") |
'uv run dbt'
|
venv_dir
|
str | Path | None
|
Directory to run |
None
|
dialect
|
str | None
|
SQL dialect for parsing (e.g. "starrocks", "mysql", "postgres"). Needed for dialect-specific syntax like backtick quoting. |
None
|
Returns:
| Type | Description |
|---|---|
dict[str, ParseResult]
|
Dict mapping model relative path -> ParseResult |
Source code in src/sqlprism/languages/dbt.py
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 | |
render_models
¶
render_models(
project_path,
model_names,
profiles_dir=None,
env_file=None,
target=None,
dbt_command="uv run dbt",
venv_dir=None,
dialect=None,
schema_catalog=None,
)
Compile specific dbt models using --select and parse the resulting SQL.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
project_path
|
str | Path
|
Path to dbt project dir (containing dbt_project.yml) |
required |
model_names
|
list[str]
|
List of model names to compile (passed to |
required |
profiles_dir
|
str | Path | None
|
Path to directory containing profiles.yml (defaults to project_path) |
None
|
env_file
|
str | Path | None
|
Optional .env file to source before running dbt compile |
None
|
target
|
str | None
|
dbt target name (default: whatever profiles.yml specifies) |
None
|
dbt_command
|
str
|
Command to invoke dbt (default: "uv run dbt") |
'uv run dbt'
|
venv_dir
|
str | Path | None
|
Directory to run |
None
|
dialect
|
str | None
|
SQL dialect for parsing. |
None
|
schema_catalog
|
dict | None
|
Optional schema catalog for column resolution. |
None
|
Returns:
| Type | Description |
|---|---|
dict[str, ParseResult]
|
Dict mapping model relative path -> ParseResult |
Source code in src/sqlprism/languages/dbt.py
135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 | |
extract_schema_yml
¶
extract_schema_yml(project_path)
Extract column definitions from dbt schema.yml files.
Scans all *.yml and *.yaml files under the project's models/
directory for model and source entries with columns: lists. Returns
a mapping of model name to ColumnDefResult entries with
source='schema_yml'. Sources are keyed as
"{source_family}.{table_name}" for backwards compat with the
pre-existing catalog flatten.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
project_path
|
str | Path
|
Path to dbt project dir (containing |
required |
Returns:
| Type | Description |
|---|---|
dict[str, list[ColumnDefResult]]
|
Dict mapping model name -> list of |
Source code in src/sqlprism/languages/dbt.py
967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 | |