Skip to content

Commit 11887fa

Browse files
authored
[DBT] Second pass at docs section (#602)
1 parent d1cd0a0 commit 11887fa

2 files changed

Lines changed: 86 additions & 15 deletions

File tree

docs/integrations/airflow.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ The name of the module file can be arbitrary, but we recommend something descrip
2828
**Note**: The name of the Engine operator is the only mandatory parameter needed for `sqlmesh.schedulers.airflow.integration.SQLMeshAirflow`. Currently supported engines are listed in the [Engine support](#engine-support) section.
2929

3030
## SQLMesh client configuration
31-
In your SQLMesh repository, create the following configuration:
31+
In your SQLMesh repository, create the following configuration within config.py:
3232
```python linenums="1"
3333
from sqlmesh.core.config import Config, AirflowSchedulerConfig
3434

docs/integrations/dbt.md

Lines changed: 85 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
# dbt
22

3-
SQLMesh provides support for the dbt project structure.
3+
SQLMesh has native support for running dbt projects. This featuring is currently under development. You can view the development backlog [here](https://github.com/orgs/TobikoData/projects/1/views/3). If you are interested in this feature, we encourage you to try it with your dbt projects and submit issues here (https://github.com/TobikoData/sqlmesh/issues), so we can make it more robust.
44

5-
## Importing a dbt project
5+
## Getting Started
6+
### Importing a dbt project
67

7-
SQLMesh supports reading an existing dbt project in order to create a new project. To initialize SQLMesh to do so, run the following command within the project root:
8+
A SQLMesh project can be configured during initialization to read from a dbt formatted project. To do so, run the following command within the dbt project root:
89

910
```bash
1011
$ sqlmesh init -t dbt
1112
```
1213

13-
The target in your `profiles.yml` file will be used by default. To use a different target, run the command above with the `--connection TARGET_NAME` command line option.
14+
The target specified in your `profiles.yml` file will be used by default. The target can be changed at anytime.
1415

1516
**Note:** Models require a start date for backfilling data through use of the `start` configuration parameter. Start can be defined for each model, or globally in the `dbt_project.yml` file as follows:
1617

@@ -19,29 +20,36 @@ The target in your `profiles.yml` file will be used by default. To use a differe
1920
> +start: Jan 1 2000
2021
```
2122

22-
## Workflow differences between SQLMesh and dbt
23+
### Running SQLMesh
24+
25+
Link to how to normally run sqlmesh here (plan, run). Continue to use your dbt format.
26+
27+
### Workflow differences between SQLMesh and dbt
2328

2429
The following are considerations when importing a dbt project:
2530

2631
* SQLMesh will detect and deploy new or modified seeds as part of running the `plan` command and applying changes. There is no separate seed command. Refer to [seed models](/concepts/models/seed_models) for more information.
27-
* The `plan` command dynamically creates environments, and therefore environments do not need to be hardcoded into your `profiles.yml` file as targets. To get the most out of SQLMesh, point your default target at the production target, and let SQLMesh handle the rest for you.
32+
* The `plan` command dynamically creates environments, and therefore environments do not need to be hardcoded into your `profiles.yml` file as targets. To get the most out of SQLMesh, point your profile target at the production target, and let SQLMesh handle the rest for you.
2833
* dbt tests are considered [audits](/concepts/audits) in SQLMesh. SQLMesh tests are [unit tests](/concepts/tests), which test query logic before applying a plan.
34+
* SQLMesh's incremental models track which intervals have been filled and automatically detects and fills interval gaps. dbt does not support intervals and their recommended incremental logic is not compatible, requiring small tweaks to the models (don't worry dbt compatibility is maintained).
2935

3036
## How to use SQLMesh incremental models within dbt
3137

32-
SQLMesh uses true incremental models, which are capable of detecting and backfilling any missing intervals. dbt's incremental logic does not support intervals, and is not compatible with SQLMesh.
38+
SQLMesh's incremental models track uses true incremental models, which are capable of detecting and backfilling any missing intervals. dbt's incremental logic does not support intervals, and is not compatible with SQLMesh.
3339

3440
### Mapping dbt incremental to SQLMesh incremental
35-
SQLMesh ensures [idempotent](/concepts/glossary#idempotency) incremental loads through the use of merge (sqlmesh calls this `incremental_by_unique_key`) and insert-overwrite (sqlmesh calls this `incremental_by_time`) incremental strategies:
41+
SQLMesh supports [idempotent](/concepts/glossary#idempotency) incremental loads through the use of merge (sqlmesh calls this `incremental_by_unique_key`) and insert-overwrite/delete+insert (sqlmesh calls this `incremental_by_time`) incremental strategies. Append is not currently supported and not recommended due to not being idempotent.
42+
43+
44+
45+
#### Merge modifications
3646

37-
1. For merge, specify the `unique_key` configuration field containing the name of the model's unique key column to use. Append is not idempotent, and therefore is not supported.
38-
2. For insert-overwrite, add a `time_column` configuration field with the value of the name of the model's time column to use.
3947

40-
### Model modifications
4148

42-
Since SQLMesh tracks intervals to deliver true incremental behavior, the dbt incremental `WHERE` statements are not compatible with SQLMesh's incremental `WHERE` statements.
49+
#### Insert-overwrite and delete+insert modifications
50+
1. For insert-overwrite, add a `time_column` configuration field with the value of the name of the model's time column to use.
4351

44-
In order to maintain backwards compatibility with dbt, SQLMesh will ignore any jinja blocks using `{% if is_incremental() %}`, and will instead ask you define a new jinja block gated by `{% if sqlmesh is defined %}`.
52+
As mentioned in the workflow changes, a small model tweak is required. In order to maintain backwards compatibility with dbt, SQLMesh will ignore any jinja blocks using `{% if is_incremental() %}`, and will instead ask you define a new jinja block gated by `{% if sqlmesh is defined %}`.
4553

4654
For example, for incremental by time using a ds `time_column`:
4755

@@ -54,6 +62,69 @@ For example, for incremental by time using a ds `time_column`:
5462
5563
For more information about how to use different time types or unique keys, refer to [incremental model kinds](/concepts/models/model_kinds).
5664
65+
### Unit Tests
66+
This is the same as sqlmesh unit tests...link to that. Yes, they go in the same folder as dbt tests (audits).
67+
68+
## Using airflow
69+
Setup airflow following the airflow docs section
70+
71+
In config.py within the project root dir, add:
72+
73+
```bash
74+
> airflow_config = sqlmesh_config(Path(__file__).parent, scheduler=AirflowSchedulerConfig())
75+
```
76+
77+
See airflow docs for AirflowSchedulerConfig configuration options.
78+
79+
80+
## Support dbt jinja methods
81+
82+
The majority of dbt jinja methods are supported. Here is a list (it'd be nice if the list was multiple columns so it wasn't so long):
83+
84+
- adapter
85+
- as_bool
86+
- as_native
87+
- as_number
88+
- as_text
89+
- api
90+
- builtins
91+
- config
92+
- env_var
93+
- exceptions
94+
- from_yaml
95+
- is_incremental (always returns false, see incremental section)
96+
- load_result
97+
- log
98+
- modules
99+
- print
100+
- project_name
101+
- ref
102+
- return
103+
- run_query
104+
- schema
105+
- set
106+
- source
107+
- statement
108+
- target
109+
- this
110+
- to_yaml
111+
- var
112+
- zip
113+
57114
## Unsupported dbt features
58115
59-
While SQLMesh can read dbt packages, it does not currently support managing those packages. Continue to use dbt deps and dbt clean to update, add, or remove packages. For more information, refer to [dbt deps](https://docs.getdbt.com/reference/commands/deps).
116+
SQLMesh is continuously adding more dbt features
117+
118+
Not an exhaustive list, but trying to catch the major features
119+
120+
dbt deps
121+
- While SQLMesh can read dbt packages, it does not currently support managing those packages. Continue to use dbt deps and dbt clean to update, add, or remove packages. For more information, refer to [dbt deps](https://docs.getdbt.com/reference/commands/deps).
122+
123+
dbt test not currently supported, but in development
124+
125+
dbt docs is not supported, snapshots not supported
126+
127+
## Missing something you need?
128+
129+
Submit an issue here (https://github.com/TobikoData/sqlmesh/issues) and we'll look into it
130+

0 commit comments

Comments
 (0)