Skip to content

Commit 014fe6a

Browse files
authored
Feat!: Create physical tables as part of evaluation (#5189)
1 parent 31763bf commit 014fe6a

37 files changed

+1232
-963
lines changed

docs/cloud/tcloud_getting_started.md

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -268,9 +268,6 @@ Models needing backfill (missing dates):
268268
├── sqlmesh_example.incremental_model: 2020-01-01 - 2024-11-24
269269
└── sqlmesh_example.seed_model: 2024-11-24 - 2024-11-24
270270
Apply - Backfill Tables [y/n]: y
271-
Creating physical tables ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 100.0% • 3/3 • 0:00:00
272-
273-
All model versions have been created successfully
274271
275272
[1/1] sqlmesh_example.seed_model evaluated in 0.00s
276273
[1/1] sqlmesh_example.incremental_model evaluated in 0.01s

docs/concepts/macros/macro_variables.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,8 @@ SQLMesh provides additional predefined variables used to modify model behavior b
130130

131131
* @runtime_stage - A string value denoting the current stage of the SQLMesh runtime. Typically used in models to conditionally execute pre/post-statements (learn more [here](../models/sql_models.md#optional-prepost-statements)). It returns one of these values:
132132
* 'loading' - The project is being loaded into SQLMesh's runtime context.
133-
* 'creating' - The model tables are being created.
134-
* 'evaluating' - The model query logic is being evaluated.
133+
* 'creating' - The model tables are being created for the first time. The data may be inserted during table creation.
134+
* 'evaluating' - The model query logic is evaluated, and the data is inserted into the existing model table.
135135
* 'promoting' - The model is being promoted in the target environment (view created during virtual layer update).
136136
* 'demoting' - The model is being demoted in the target environment (view dropped during virtual layer update).
137137
* 'auditing' - The audit is being run.

docs/examples/incremental_time_full_walkthrough.md

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -304,10 +304,6 @@ Models needing backfill (missing dates):
304304
Enter the backfill start date (eg. '1 year', '2020-01-01') or blank to backfill from the beginning of history:
305305
Enter the backfill end date (eg. '1 month ago', '2020-01-01') or blank to backfill up until now:
306306
Apply - Backfill Tables [y/n]: y
307-
Creating physical table ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 100.0% • 1/1 • 0:00:07
308-
309-
All model versions have been created successfully
310-
311307
[1/1] demo__dev.incrementals_demo evaluated in 6.97s
312308
Evaluating models ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 100.0% • 1/1 • 0:00:06
313309

@@ -640,9 +636,10 @@ Models:
640636
├── tcloud_raw_data.product_usage
641637
└── tcloud_raw_data.sales
642638
Apply - Virtual Update [y/n]: y
643-
Creating physical tables ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 100.0% • 15/15 • 0:00:03
644639
645-
All model versions have been created successfully
640+
SKIP: No physical layer updates to perform
641+
642+
SKIP: No model batches to execute
646643
647644
Virtually Updating 'prod' ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 100.0% • 0:00:02
648645
@@ -732,10 +729,6 @@ Models needing backfill (missing dates):
732729
Enter the preview start date (eg. '1 year', '2020-01-01') or blank to backfill to preview starting from yesterday: 2024-10-27
733730
Enter the preview end date (eg. '1 month ago', '2020-01-01') or blank to preview up until '2024-11-08 00:00:00':
734731
Apply - Preview Tables [y/n]: y
735-
Creating physical table ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 100.0% • 1/1 • 0:00:16
736-
737-
All model versions have been created successfully
738-
739732
[1/1] demo__dev.incrementals_demo evaluated in 6.18s
740733
Evaluating models ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 100.0% • 1/1 • 0:00:06
741734
@@ -1249,9 +1242,10 @@ Models:
12491242
THEN 'Regular User'
12501243
Directly Modified: demo.incrementals_demo (Forward-only)
12511244
Apply - Virtual Update [y/n]: y
1252-
Creating physical tables ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 100.0% • 15/15 • 0:00:02
12531245
1254-
All model versions have been created successfully
1246+
SKIP: No physical layer updates to perform
1247+
1248+
SKIP: No model batches to execute
12551249
12561250
Virtually Updating 'prod' ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 100.0% • 0:00:02
12571251

docs/integrations/dlt.md

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,10 +102,6 @@ Models needing backfill (missing dates):
102102
├── sushi_dataset_sqlmesh.incremental_sushi_types: 2024-10-03 - 2024-10-03
103103
└── sushi_dataset_sqlmesh.incremental_waiters: 2024-10-03 - 2024-10-03
104104
Apply - Backfill Tables [y/n]: y
105-
Creating physical table ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 100.0% • 3/3 • 0:00:00
106-
107-
All model versions have been created successfully
108-
109105
[1/1] sushi_dataset_sqlmesh.incremental__dlt_loads evaluated in 0.01s
110106
[1/1] sushi_dataset_sqlmesh.incremental_sushi_types evaluated in 0.00s
111107
[1/1] sushi_dataset_sqlmesh.incremental_waiters evaluated in 0.01s

examples/multi/repo_1/models/a.sql

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
MODEL (
2-
name bronze.a
2+
name bronze.a,
3+
kind FULL
34
);
45

56
SELECT

examples/multi/repo_1/models/b.sql

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
MODEL (
2-
name bronze.b
2+
name bronze.b,
3+
kind FULL
34
);
45

56
SELECT

examples/multi/repo_2/models/c.sql

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
MODEL (
2-
name silver.c
2+
name silver.c,
3+
kind FULL
34
);
45

56
SELECT DISTINCT col_a

examples/multi/repo_2/models/d.sql

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
MODEL (
2-
name silver.d
2+
name silver.d,
3+
kind FULL
34
);
45

56
SELECT

examples/multi/repo_2/models/e.sql

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
MODEL (
2-
name silver.e
2+
name silver.e,
3+
kind FULL
34
);
45

56
SELECT

examples/sushi/config.py

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import os
22

3-
from sqlmesh.core.config.common import VirtualEnvironmentMode
3+
from sqlmesh.core.config.common import VirtualEnvironmentMode, TableNamingConvention
44
from sqlmesh.core.config import (
55
AutoCategorizationMode,
66
BigQueryConnectionConfig,
@@ -27,6 +27,11 @@
2727
defaults = {"dialect": "duckdb"}
2828
model_defaults = ModelDefaultsConfig(**defaults)
2929
model_defaults_iceberg = ModelDefaultsConfig(**defaults, storage_format="iceberg")
30+
before_all = [
31+
"CREATE SCHEMA IF NOT EXISTS raw",
32+
"DROP VIEW IF EXISTS raw.demographics",
33+
"CREATE VIEW raw.demographics AS (SELECT 1 AS customer_id, '00000' AS zip)",
34+
]
3035

3136

3237
# A DuckDB config, in-memory by default.
@@ -52,6 +57,7 @@
5257
"nomissingexternalmodels",
5358
],
5459
),
60+
before_all=before_all,
5561
)
5662

5763
bigquery_config = Config(
@@ -63,6 +69,7 @@
6369
},
6470
default_gateway="bq",
6571
model_defaults=model_defaults,
72+
before_all=before_all,
6673
)
6774

6875
# A configuration used for SQLMesh tests.
@@ -75,6 +82,7 @@
7582
)
7683
),
7784
model_defaults=model_defaults,
85+
before_all=before_all,
7886
)
7987

8088
# A configuration used for SQLMesh tests with virtual environment mode set to DEV_ONLY.
@@ -84,14 +92,15 @@
8492
"plan": PlanConfig(
8593
auto_categorize_changes=CategorizerConfig.all_full(),
8694
),
87-
}
95+
},
8896
)
8997

9098
# A DuckDB config with a physical schema map.
9199
map_config = Config(
92100
default_connection=DuckDBConnectionConfig(),
93101
physical_schema_mapping={"^sushi$": "company_internal"},
94102
model_defaults=model_defaults,
103+
before_all=before_all,
95104
)
96105

97106
# A config representing isolated systems with a gateway per system
@@ -103,6 +112,7 @@
103112
},
104113
default_gateway="dev",
105114
model_defaults=model_defaults,
115+
before_all=before_all,
106116
)
107117

108118
required_approvers_config = Config(
@@ -137,19 +147,21 @@
137147
),
138148
],
139149
model_defaults=model_defaults,
150+
before_all=before_all,
140151
)
141152

142153

143154
environment_suffix_table_config = Config(
144155
default_connection=DuckDBConnectionConfig(),
145156
model_defaults=model_defaults,
146157
environment_suffix_target=EnvironmentSuffixTarget.TABLE,
158+
before_all=before_all,
147159
)
148160

149161
environment_suffix_catalog_config = environment_suffix_table_config.model_copy(
150162
update={
151163
"environment_suffix_target": EnvironmentSuffixTarget.CATALOG,
152-
}
164+
},
153165
)
154166

155167
CATALOGS = {
@@ -161,6 +173,7 @@
161173
default_connection=DuckDBConnectionConfig(catalogs=CATALOGS),
162174
default_test_connection=DuckDBConnectionConfig(catalogs=CATALOGS),
163175
model_defaults=model_defaults,
176+
before_all=before_all,
164177
)
165178

166179
environment_catalog_mapping_config = Config(
@@ -177,4 +190,13 @@
177190
"^prod$": "prod_catalog",
178191
".*": "dev_catalog",
179192
},
193+
before_all=before_all,
194+
)
195+
196+
hash_md5_naming_config = config.copy(
197+
update={"physical_table_naming_convention": TableNamingConvention.HASH_MD5}
198+
)
199+
200+
table_only_naming_config = config.copy(
201+
update={"physical_table_naming_convention": TableNamingConvention.TABLE_ONLY}
180202
)

0 commit comments

Comments
 (0)