Indexer (Orchestrator)¶
Orchestrates the indexing pipeline: scan repos, checksum files, dispatch to parsers, store results.
Indexer
¶
Indexer(graph)
Orchestrates parsing and indexing across repos.
Connects language parsers to the GraphDB storage layer. Handles
file scanning, checksum diffing, dialect resolution, and batch
insertion of parse results. Supports plain SQL repos, sqlmesh
projects, and dbt projects.
Initialise the indexer.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
graph
|
GraphDB
|
The |
required |
Source code in src/sqlprism/core/indexer.py
38 39 40 41 42 43 44 45 46 47 48 49 50 | |
get_parser
¶
get_parser(dialect=None)
Get or create a SqlParser for the given dialect.
Source code in src/sqlprism/core/indexer.py
52 53 54 55 56 | |
get_sqlmesh_renderer
¶
get_sqlmesh_renderer(dialect=None)
Get or create a SqlMeshRenderer with the correct dialect parser.
Source code in src/sqlprism/core/indexer.py
58 59 60 61 62 63 64 | |
reindex_repo
¶
reindex_repo(
name, path, dialect=None, dialect_overrides=None
)
Reindex a single repo by scanning for SQL files.
Compares file checksums against the stored index to determine added, changed, and deleted files. Only changed files are re-parsed.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Repo name in the index. |
required |
path
|
str | Path
|
Absolute path to the repo root. |
required |
dialect
|
str | None
|
Default SQL dialect (e.g. |
None
|
dialect_overrides
|
dict[str, str] | None
|
Per-path dialect overrides as
|
None
|
Returns:
| Type | Description |
|---|---|
dict
|
Stats dict with keys |
dict
|
|
dict
|
|
dict
|
|
dict
|
|
Source code in src/sqlprism/core/indexer.py
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 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 134 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 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 | |
reindex_sqlmesh
¶
reindex_sqlmesh(
repo_name,
project_path,
env_file=None,
variables=None,
dialect="athena",
sqlmesh_command="uv run python",
venv_dir=None,
)
Index a sqlmesh project by rendering all models first.
Uses SqlMeshRenderer to render every model via subprocess,
then parses the rendered SQL and inserts results into the graph.
When source files haven't changed (matching fingerprint), skips the expensive rendering subprocess and re-parses cached SQL with the current schema catalog. This allows schema enrichment (SELECT * expansion) to converge while avoiding redundant rendering.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
repo_name
|
str
|
Repo name in the index. |
required |
project_path
|
str | Path
|
Path to the sqlmesh project directory
(containing |
required |
env_file
|
str | Path | None
|
Optional |
None
|
variables
|
dict[str, str | int] | None
|
Extra sqlmesh variables (e.g. |
None
|
dialect
|
str
|
SQL dialect for rendering (default |
'athena'
|
sqlmesh_command
|
str
|
Command to invoke Python in the sqlmesh venv. |
'uv run python'
|
venv_dir
|
str | Path | None
|
Directory containing |
None
|
Returns:
| Type | Description |
|---|---|
dict
|
Stats dict with keys |
dict
|
|
Source code in src/sqlprism/core/indexer.py
206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 | |
reindex_dbt
¶
reindex_dbt(
repo_name,
project_path,
profiles_dir=None,
env_file=None,
target=None,
dbt_command="uv run dbt",
venv_dir=None,
dialect=None,
)
Index a dbt project by compiling all models first.
Runs dbt compile via DbtRenderer, then parses each
compiled SQL file and inserts results into the graph.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
repo_name
|
str
|
Repo name in the index. |
required |
project_path
|
str | Path
|
Path to the dbt project directory
(containing |
required |
profiles_dir
|
str | Path | None
|
Path to the directory containing |
None
|
env_file
|
str | Path | None
|
Optional |
None
|
target
|
str | None
|
dbt target name override. |
None
|
dbt_command
|
str
|
Command to invoke dbt (e.g. |
'uv run dbt'
|
venv_dir
|
str | Path | None
|
Directory to run from (where |
None
|
dialect
|
str | None
|
SQL dialect for parsing compiled output. |
None
|
Returns:
| Type | Description |
|---|---|
dict
|
Stats dict with keys |
dict
|
|
Source code in src/sqlprism/core/indexer.py
341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 | |
reindex_files
¶
reindex_files(paths, repo_configs=None)
Reindex specific files. Fast path for on-save.
Resolves each path to its repo, determines repo type (plain SQL, dbt, sqlmesh), and reindexes accordingly.
For plain SQL: read, parse, insert immediately.
For dbt/sqlmesh: call render_models() for the affected models,
then parse and insert the rendered SQL.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
paths
|
list[str | Path]
|
Absolute file paths that changed. Non-SQL files and files outside configured repos are silently skipped. |
required |
repo_configs
|
dict | None
|
Optional repo config dict (repo_name → config). Required for dbt/sqlmesh repos to pass renderer params. If not provided, only plain SQL repos are supported. |
None
|
Returns:
| Type | Description |
|---|---|
dict
|
Stats dict with |
dict
|
|
Source code in src/sqlprism/core/indexer.py
426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 | |
parse_file
¶
parse_file(file_path, content, dialect=None, schema=None)
Parse a single SQL file without writing to the database.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file_path
|
str
|
File path (used for naming nodes, not read from disk). |
required |
content
|
str
|
Raw SQL content. |
required |
dialect
|
str | None
|
Optional SQL dialect override. |
None
|
schema
|
dict | None
|
Optional schema catalog for |
None
|
Returns:
| Type | Description |
|---|---|
ParseResult
|
A |
ParseResult
|
and lineage. Returns an empty result for non-SQL files. |
Source code in src/sqlprism/core/indexer.py
1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 | |
parse_file_at_commit
¶
parse_file_at_commit(
repo_path, file_path, commit, dialect=None
)
Parse a file at a specific git commit.
Retrieves file content via git show and parses it without
writing to the database. Used by pr_impact analysis.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
repo_path
|
Path
|
Absolute path to the git repo root. |
required |
file_path
|
str
|
Relative file path within the repo. |
required |
commit
|
str
|
Git commit hash or ref to read from. |
required |
dialect
|
str | None
|
Optional SQL dialect override. |
None
|
Returns:
| Type | Description |
|---|---|
ParseResult | None
|
A |
ParseResult | None
|
that commit or is not a SQL file. |
Source code in src/sqlprism/core/indexer.py
1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 | |
get_changed_files
¶
get_changed_files(repo_path, base_commit)
Get SQL files changed between a base commit and HEAD.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
repo_path
|
Path
|
Absolute path to the git repo root. |
required |
base_commit
|
str
|
Git commit hash or ref to diff against HEAD. |
required |
Returns:
| Type | Description |
|---|---|
list[str]
|
List of relative file paths for changed SQL files. Returns |
list[str]
|
an empty list on git errors or timeouts. |
Source code in src/sqlprism/core/indexer.py
1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 | |