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
This allows you to tailor the behavior of models for each gateway without affecting the global model_defaults.
974
+
975
+
For example, you can adjust dialect-specific behavior, like the normalization to be case insensitive, to better match the engine’s requirements and avoid compatibility issues.
976
+
977
+
951
978
#### Model Kinds
952
979
953
980
Model kinds are required in each model file's `MODEL` DDL statement. They may optionally be used to specify a default kind in the model defaults configuration key.
Organizations typically connect to a data warehouse through a single engine to ensure data consistency. However, there are cases where the processing capabilities of one engine may be better suited to specific tasks than another.
4
4
5
-
By decoupling storage from computeand with growing support for open table formats like Apache Iceberg and Hive, different engines can now interact with the same data.
5
+
Across the industry, companies are increasingly decoupling storage from compute, demanding interoperability across platforms and tools, focusing on cost efficiency and a growing support for open table formats like Apache Iceberg and Hive.
6
6
7
-
With SQLMesh's new multi-engine feature, users can leverage multiple engine adapters within a single project, offering the flexibility to choose the best engine for each task.
7
+
In SQLMesh, you can use multiple engine adapters within a single project, giving you the flexibility to choose the most suitable engine for each task. This allows individual models to run on a specified engine based on their specific requirements.
8
8
9
-
This feature allows you to run each model on a specified engine, provided the data catalog is shared and the engines support read/write operations on it.
9
+
## Configuring a Project with Multiple Engines
10
10
11
+
Configuring your project to use multiple engines follows a simple process:
11
12
12
-
## Configuring project with multiple engines
13
+
- Include all required [gateway connections](../reference/configuration.md#connection) in your configuration.
14
+
- Specify the `gateway` to be used for execution in the `MODEL` DDL.
13
15
14
-
To configure a SQLMesh project with multiple engines, simply include all required gateway [connections](../reference/configuration.md#connection) in your configuration.
16
+
If no gateway is explicitly defined for a model, the [default_gateway](../reference/configuration.md#default-gateway) of the project is used.
15
17
16
-
Next, specify the appropriate `gateway` in the `MODEL` DDL for each model. If no gateway is explicitly defined, the default gateway will be used.
18
+
By default, the `default_gateway` is also responsible to create the views of the virtual layer. This assumes that all engines can read from and write to the same shared catalog.
17
19
18
-
The [virtual layer](../concepts/glossary.md#virtual-layer)will be created within the engine corresponding to the default gateway.
20
+
Alternatively, you can configure the model-specific gateway to create the views of the virtual layer by setting [gateway_managed_virtual_layer](#gateway-managed-virtual-layer)flag in your configuration to true.
19
21
20
-
### Example
22
+
### Shared Virtual Layer
21
23
22
-
Below is a simple example of setting up a project with connections to both DuckDB and PostgreSQL.
24
+
To dive deeper, in SQLMesh the [physical layer](../concepts/glossary.md#physical-layer) is the concrete data storage layer, where it stores and manages data in database tables and materialized views.
25
+
26
+
While, the [virtual layer](../concepts/glossary.md#virtual-layer) consists of views, one for each model, each pointing to a snapshot table in the physical layer.
27
+
28
+
In a multi-engine project with a shared data catalog, the model-specific gateway is responsible for the physical layer, while the default gateway is used for managing the virtual layer.
29
+
30
+
#### Example: DuckDB + PostgreSQL
23
31
24
-
In this setup, the PostgreSQL engine is set as the default, so it will be used to manage views in the virtual layer.
32
+
Below is a simple example of setting up a project with connections to both DuckDB and PostgreSQL.
25
33
26
-
Meanwhile, the DuckDB's [attach](https://duckdb.org/docs/sql/statements/attach.html) feature enables read-write access to the PostgreSQL catalog's physical tables.
34
+
In this setup, the PostgreSQL engine is set as the default, so it will be used to manage views in the virtual layer. Meanwhile, the DuckDB's [attach](https://duckdb.org/docs/sql/statements/attach.html) feature enables read-write access to the PostgreSQL catalog's physical tables.
27
35
28
36
=== "YAML"
29
37
@@ -81,7 +89,7 @@ Meanwhile, the DuckDB's [attach](https://duckdb.org/docs/sql/statements/attach.h
81
89
port=5432,
82
90
user="postgres",
83
91
password="password",
84
-
database="main_db",
92
+
database="main_db",
85
93
)
86
94
),
87
95
},
@@ -91,6 +99,7 @@ Meanwhile, the DuckDB's [attach](https://duckdb.org/docs/sql/statements/attach.h
91
99
92
100
Given this configuration, when a model’s gateway is set to duckdb, it will be materialized within the PostgreSQL `main_db` catalog, but it will be evaluated using DuckDB’s engine.
93
101
102
+
Given this configuration, when a model’s gateway is set to duckdb, it will be materialized within the PostgreSQL `main_db` catalog, but it will be evaluated using DuckDB’s engine.
In this model, the DuckDB engine can be used to scan and load data from an iceberg table and create the physical table in the PostgreSQL database.
118
+
In the `order_ship_date` model, the DuckDB engine is set, which will be used to create the physical table in the PostgreSQL database.
119
+
120
+
This allows you to efficiently scan data from an Iceberg table, or even query tables directly from S3 when used with the [HTTPFS](https://duckdb.org/docs/stable/extensions/httpfs/overview.html) extension.
In models where no gateway is specified, such as the `customer_orders` model, the default PostgreSQL engine will be used to create the physical table as well as to create and manage the views of the virtual layer.
125
+
126
+
### Gateway-Managed Virtual Layer
127
+
128
+
For projects where the engines don’t share a catalog or your raw data is located in different warehouses, you may prefer each gateway to manage its own virtual layer. This ensures isolation and each model’s views being created by its respective gateway.
129
+
130
+
To enable this, set `gateway_managed_virtual_layer` to `true` in your configuration. By default, this flag is set to false.
131
+
132
+
#### Example: Redshift + Athena + Snowflake
133
+
134
+
Consider a scenario where you need to create a project with models in Redshift, Athena and Snowflake. To set this you, add the connections to your configuration and set the `gateway_managed_virtual_layer` flag:
Note that gateway-specific variables take precedence over global ones. In the example above, the `gw_var` used in a model will take the value defined for the respective gateway.
234
+
235
+
For further customization, you can also enable [gateway-specific model defaults](../guides/configuration.md#gateway-specific-model-defaults). This allows you to define custom behaviors, such as specifying a dialect with case-insensitivity normalization.
236
+
237
+
```sql linenums="1"
238
+
MODEL (
239
+
name redshift_schema.order_dates,
240
+
table_format iceberg,
241
+
);
242
+
243
+
SELECT
244
+
order_date,
245
+
order_id
246
+
FROM
247
+
bucket.raw_data;
248
+
```
249
+
250
+
In this setup, since the default gateway is set to redshift, omitting the gateway from a model will default to this, as seen in the `order_dates` model above.
251
+
252
+
```sql linenums="1"
253
+
MODEL (
254
+
name athena_schema.order_status,
255
+
table_format iceberg,
256
+
gateway athena,
257
+
);
258
+
259
+
SELECT
260
+
order_id,
261
+
status
262
+
FROM
263
+
bucket.raw_data;
264
+
```
265
+
266
+
While in the case of the `athena_schema.order_status` model above, the gateway is specified to athena explicitly.
267
+
268
+
```sql linenums="1"
269
+
MODEL (
270
+
name snowflake_schema.customer_orders,
271
+
table_format iceberg,
272
+
gateway snowflake
273
+
);
274
+
275
+
SELECT
276
+
customer_id,
277
+
orders
278
+
FROM
279
+
bronze_schema.customer_data;
280
+
```
281
+
282
+
Finally, specifying the snowflake gateway for the `customer_orders` model ensures it is isolated from the rest and sources from a table within the snowflake database.
When you run the plan, the catalogs for each model will be set automatically based on the gateway’s connection and each corresponding model will be evaluated against the specified engine.
The views of the virtual layer will also be created by each corresponding engine.
306
+
307
+
This approach provides isolation between your models, while maintaining centralized control over your project.
110
308
111
-
While the PostgreSQL engine is responsible for creating the model's view for the virtual layer.
309
+
This allows users to leverage multiple engines within a single SQLMesh project, particularly as the industry shifts toward data lakes, open table formats, and greater interoperability.
Copy file name to clipboardExpand all lines: docs/reference/configuration.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -35,7 +35,7 @@ Configuration options for SQLMesh environment creation and promotion.
35
35
|`physical_schema_override`| (Deprecated) Use `physical_schema_mapping` instead. A mapping from model schema names to names of schemas in which physical tables for the corresponding models will be placed. | dict[string, string]| N |
36
36
|`physical_schema_mapping`| A mapping from regular expressions to names of schemas in which physical tables for the corresponding models [will be placed](../guides/configuration.md#physical-table-schemas). (Default physical schema name: `sqlmesh__[model schema]`) | dict[string, string]| N |
37
37
|`environment_suffix_target`| Whether SQLMesh views should append their environment name to the `schema` or `table` - [additional details](../guides/configuration.md#view-schema-override). (Default: `schema`) | string | N |
38
-
|`gateway_managed_virtual_layer`| Whether SQLMesh views of the virtual layer will be created by the default gateway or model specified gateways - [additional details](../guides/configuration.md#view-schema-override). (Default: False) | boolean | N |
38
+
|`gateway_managed_virtual_layer`| Whether SQLMesh views of the virtual layer will be created by the default gateway or model specified gateways - [additional details](../guides/multi_engine.md#gateway-managed-virtual-layer). (Default: False) | boolean | N |
39
39
|`environment_catalog_mapping`| A mapping from regular expressions to catalog names. The catalog name is used to determine the target catalog for a given environment. | dict[string, string]| N |
40
40
|`log_limit`| The default number of logs to keep (Default: `20`) | int | N |
0 commit comments