You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
SQLMesh's core commands have multiple options that alter their behavior. Some of those options streamline the SQLMesh `plan` workflow and CLI output.
126
126
127
-
If you prefer a streamlined workflow (no prompts, no diff previews, auto-apply changes), choose the `FLOW` CLI mode to automatically include those options in your project configuration file. If you prefer to see all the output SQLMesh provides, choose `DEFAULT` mode.
127
+
If you prefer a streamlined workflow (no prompts, no file diff previews, auto-apply changes), choose the `FLOW` CLI mode to automatically include those options in your project configuration file.
128
+
129
+
If you prefer to see all the output SQLMesh provides, choose `DEFAULT` mode, which we will use in this quickstart:
128
130
129
131
```bash
130
132
Choose your SQLMesh CLI experience:
@@ -147,18 +149,18 @@ If you chose a different engine, add your engine's connection information to the
147
149
Your SQLMesh project is ready!
148
150
149
151
Next steps:
150
-
• Update your gateway connection settings (e.g., username/password) in the project configuration file:
??? info "Learn more about the project's configuration: `config.yaml`"
@@ -212,7 +214,7 @@ Need help?
212
214
213
215
Learn more about SQLMesh project configuration [here](../reference/configuration.md).
214
216
215
-
The scaffold will also include multiple directories where SQLMesh project files are stored and multiple files that constitute the example project (e.g., SQL models).
217
+
The scaffold generator creates multiple directories where SQLMesh project files are stored and multiple files that constitute the example project (e.g., SQL models).
216
218
217
219
??? info "Learn more about the project directories and files"
218
220
SQLMesh uses a scaffold generator to initiate a new project. The generator will create multiple sub-directories and files for organizing your SQLMesh project code.
@@ -245,7 +247,7 @@ The scaffold will also include multiple directories where SQLMesh project files
245
247
- ./tests
246
248
- test_full_model.yaml
247
249
248
-
Finally, the scaffold will include data for the example project to use.
250
+
Finally, the scaffold generator creates data for the example project to use.
249
251
250
252
??? info "Learn more about the project's data"
251
253
The data used in this example project is contained in the `seed_data.csv` file in the `/seeds` project directory. The data reflects sales of 3 items over 7 days in January 2020.
@@ -291,7 +293,7 @@ The first SQLMesh plan must execute every model to populate the production envir
Line 3 of the output notes that `sqlmesh plan` successfully executed the project's test `tests/test_full_model.yaml` with duckdb.
312
314
313
-
Line 5 describes what environments the plan will affect when applied - a new `prod` environment in this case.
314
-
315
-
Lines 7-11 of the output show that SQLMesh detected three new models relative to the current empty environment.
315
+
Line 6 describes what environments the plan will affect when applied - a new `prod` environment in this case.
316
316
317
-
Lines 12-16 list each model that will be executed by the plan, along with the date intervals or refresh types. For both `full_model` and `seed_model`, it shows `[full refresh]`, while for `incremental_model` it shows a specific date range `[2020-01-01 - 2025-04-17]`. The incremental model date range begins from 2020-01-01 because the `full` model kind always fully rebuilds its table.
317
+
Lines 8-12 of the output show that SQLMesh detected three new models relative to the current empty environment.
318
318
319
-
The `seed_model` date range begins on the same day the plan was made because `SEED` models have no temporality associated with them other than whether they have been modified since the previous SQLMesh plan.
319
+
Lines 13-16 list each model that will be executed by the plan, along with the date intervals or refresh types. For both `full_model` and `seed_model`, it shows `[full refresh]`, while for `incremental_model` it shows a specific date range `[2020-01-01 - 2025-06-22]`. The incremental model date range begins from 2020-01-01 because its definition specifies a model start date of `2020-01-01`.
320
320
321
321
??? info "Learn more about the project's models"
322
322
@@ -393,23 +393,23 @@ The `seed_model` date range begins on the same day the plan was made because `SE
393
393
GROUP BY item_id
394
394
```
395
395
396
-
Line 16 asks you whether to proceed with executing the model backfills described in lines 11-14. Enter `y` and press `Enter`, and SQLMesh will execute the models and return this output:
396
+
Line 18 asks you whether to proceed with executing the model backfills described in lines 13-16. Enter `y` and press `Enter`, and SQLMesh will execute the models and return this output:
@@ -428,7 +428,89 @@ Lines 12-14 show the progress and completion of the second step - executing mode
428
428
429
429
Lines 16-18 show the progress and completion of the final step - virtually updating the plan's target environment, which makes the data available for querying.
430
430
431
-
You've now created a new production environment with all of history backfilled.
431
+
??? "Learn more about the plan's actions"
432
+
433
+
Before applying a plan, you can view a detailed description of the actions it will take by passing the explain flag in your `sqlmesh plan` command:
434
+
435
+
```bash
436
+
sqlmesh plan --explain
437
+
```
438
+
439
+
Passing the explain flag for the quickstart example project above adds the following information to the output:
440
+
441
+
```bash
442
+
Explained plan
443
+
├── Validate SQL and create physical layer tables and views if they do not exist
│ ├── Dry run model query without inserting results
479
+
│ └── Create table if it doesn't exist
480
+
```
481
+
482
+
The first line shows the model name `sqlmesh_example.seed_model` and the physical layer table SQLMesh will create to store its data: `db.sqlmesh__sqlmesh_example.sqlmesh_example__seed_model__2185867172`. The second and third lines tell us that in this step SQLMesh will dry-run the model query and create the physical layer table if it doesn't exist.
483
+
484
+
The second section describes what will occur during the backfill step. The second model in this section is:
The first line shows the model name `sqlmesh_example.full_model` and the physical layer table SQLMesh will insert the model's data into: `db.sqlmesh__sqlmesh_example.sqlmesh_example__full_model__2278521865`. The second and third lines tell us that the backfill action will fully refresh the model's physical table and run the `assert_positive_order_ids` audit.
493
+
494
+
The final section describes SQLMesh's action during the virtual layer update step. The first model in this section is:
495
+
496
+
```bash
497
+
└── Create or update views in the virtual layer to point at new physical tables and views
The virtual layer step will update the `sqlmesh_example.full_model` virtual layer view to `SELECT * FROM` the physical table `db.sqlmesh__sqlmesh_example.sqlmesh_example__full_model__2278521865`.
502
+
503
+
Let's take a quick look at the project's DuckDB database file to see the objects SQLMesh created. First, we open the built-in DuckDB CLI tool with the `duckdb db.db` command, then run our two queries:
504
+
505
+
Our first query shows the three physical tables SQLMesh created in the `sqlmesh__sqlmesh_example` schema (one table for each model):
506
+
507
+

508
+
509
+
Our second query shows that in the `sqlmesh` schema SQLMesh created three virtual layer views that read from the three physical tables:
510
+
511
+

512
+
513
+
You've now created a new production environment with all of history backfilled!
0 commit comments