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.
- Python filesSources, models, components, and checks that you write.
- GraphSelectJoin loads the files and records which unit reads which.
- CheckColumn names, types, and grains are verified across the graph.
- SQLEach model compiles to a query you can read and review.
- Your toolsA scheduler, dbt, Looker, or Airflow runs or reads the output.
What a project contains
Section titled “What a project contains”| 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.
What happens when you run a command
Section titled “What happens when you run a command”- Load. SelectJoin imports each file in
sources/andmodels/and calls itsbuild()function. The function returns a query object, not a string. - Link. Every
refandsourcecall inside a query becomes an edge in the dependency graph. - 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.
- 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.
What SelectJoin does not do
Section titled “What SelectJoin does not do”- 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 checkvalidates definitions; a data check is a query you run later with your own tools.
Where it sits in a stack
Section titled “Where it sits in a stack”| 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 |