Skip to content

How SelectJoin works

SelectJoin is a compiler. You describe tables and queries in Python, and it produces SQL text. It never connects to a database, so everything below happens on your machine, from files.

  1. Python filesSources, models, components, and checks that you write.
  2. GraphSelectJoin loads the files and records which unit reads which.
  3. CheckColumn names, types, and grains are verified across the graph.
  4. SQLEach model compiles to a query you can read and review.
  5. Your toolsA scheduler, dbt, Looker, or Airflow runs or reads the output.
Piece What it is Where it lives
Source A physical table you read from, with its columns and types sources/
Model A query built from sources and other models models/
Component An ordinary Python function that several models share components/
Check A data quality rule that compiles to a query checks.py

Sources and models are called units. Every unit has a unique name, and models refer to other units by that name with ref("name") or source("name"). Those references are the only thing that decides the order of the graph.

  1. Load. SelectJoin imports each file in sources/ and models/ and calls its build() function. The function returns a query object, not a string.
  2. Link. Every ref and source call inside a query becomes an edge in the dependency graph.
  3. Analyze. Starting from the column types you declared on sources, SelectJoin works out the output columns and types of every model. A column that does not exist, a grain that is not in the output, or a union with mismatched columns fails here, with the file and a suggestion.
  4. Compile. To produce SQL for one model, SelectJoin places each upstream unit in a named CTE, in dependency order, and renders the result in your dialect.

Steps 1 to 3 are what selectjoin check runs. Step 4 is selectjoin compile.

Because the query is an object until the last step, the same project can be rendered in another dialect, as dbt models, as LookML views, or as an Airflow DAG, without changing the Python.

  • It does not connect to a warehouse, so it needs no credentials.
  • It does not run SQL, so no command can change data.
  • It does not discover schemas. The column types on a source are a contract you write, or import from a metadata snapshot or a dbt project.
  • It does not test data. selectjoin check validates definitions; a data check is a query you run later with your own tools.
You keep SelectJoin adds
Your warehouse Nothing runs there until you run the SQL
Your scheduler or dbt The SQL files, dbt models, or DAG it executes
Your BI tool Typed, described tables, and LookML views for Looker
Code review Python you can diff, plus the compiled SQL to read
Term Meaning
Unit A source or a model
Grain The column or columns that identify one row of a model’s output
Layer An optional category for a model, such as staging or marts, with a folder and a name prefix
Materialization How a model becomes an object in the warehouse: view, table, incremental, or ephemeral
Relation The table name a model is built as, when it differs from the model’s name
Package Another project, such as a dbt project, whose models you reference but do not own

Next: how a project is laid out on disk.