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
Copy file name to clipboardExpand all lines: docs/guides/configuration.md
+89-2Lines changed: 89 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -320,10 +320,14 @@ The cache directory is automatically created if it doesn't exist. You can clear
320
320
321
321
SQLMesh creates schemas, physical tables, and views in the data warehouse/engine. Learn more about why and how SQLMesh creates schema in the ["Why does SQLMesh create schemas?" FAQ](../faq/faq.md#schema-question).
322
322
323
-
The default SQLMesh behavior described in the FAQ is appropriate for most deployments, but you can override where SQLMesh creates physical tables and views with the `physical_schema_mapping`, `environment_suffix_target`, and `environment_catalog_mapping` configuration options. These options are in the [environments](../reference/configuration.md#environments) section of the configuration reference page.
323
+
The default SQLMesh behavior described in the FAQ is appropriate for most deployments, but you can override *where* SQLMesh creates physical tables and views with the `physical_schema_mapping`, `environment_suffix_target`, and `environment_catalog_mapping` configuration options.
324
+
325
+
You can also override *what* the physical tables are called by using the `physical_table_naming_convention` option.
326
+
327
+
These options are in the [environments](../reference/configuration.md#environments) section of the configuration reference page.
324
328
325
329
#### Physical table schemas
326
-
By default, SQLMesh creates physical tables for a model with a naming convention of `sqlmesh__[model schema]`.
330
+
By default, SQLMesh creates physical schemas for a model with a naming convention of `sqlmesh__[model schema]`.
327
331
328
332
This can be overridden on a per-schema basis using the `physical_schema_mapping` option, which removes the `sqlmesh__` prefix and uses the [regex pattern](https://docs.python.org/3/library/re.html#regular-expression-syntax) you provide to map the schemas defined in your model to their corresponding physical schemas.
329
333
@@ -436,6 +440,89 @@ Given the example of a model called `my_schema.users` with a default catalog of
436
440
- Using `environment_suffix_target: catalog` only works on engines that support querying across different catalogs. If your engine does not support cross-catalog queries then you will need to use `environment_suffix_target: schema` or `environment_suffix_target: table` instead.
437
441
- Automatic catalog creation is not supported on all engines even if they support cross-catalog queries. For engines where it is not supported, the catalogs must be managed externally from SQLMesh and exist prior to invoking SQLMesh.
438
442
443
+
#### Physical table naming convention
444
+
445
+
Out of the box, SQLMesh has the following defaults set:
Given a catalog of `warehouse` and a model named `finance_mart.transaction_events_over_threshold`, this causes SQLMesh to create physical tables using the following convention:
This deliberately contains some redundancy with the *model* schema as it's repeated at the physical layer in both the physical schema name as well as the physical table name.
459
+
460
+
##### Table only
461
+
462
+
Some engines have object name length limitations which cause them to [silently truncate](https://www.postgresql.org/docs/current/sql-syntax-lexical.html#SQL-SYNTAX-IDENTIFIERS) table and view names that exceed this limit. This behaviour breaks SQLMesh, so we raise a runtime error if we detect the engine would silently truncate the name of the table we are trying to create.
463
+
464
+
Having redundancy in the physical table names does reduce the number of characters that can be utilised in model names. To increase the number of characters available to model names, you can use `physical_table_naming_convention` like so:
465
+
466
+
=== "YAML"
467
+
468
+
```yaml linenums="1"
469
+
physical_table_naming_convention: table_only
470
+
```
471
+
472
+
=== "Python"
473
+
474
+
```python linenums="1"
475
+
from sqlmesh.core.config import Config, ModelDefaultsConfig, TableNamingConvention
Notice that the model schema name is no longer part of the physical table name. This allows for slightly longer model names on engines with low identifier length limits, which may be useful for your project.
491
+
492
+
##### MD5 hash
493
+
494
+
If you *still* need more characters, you can set `physical_table_naming_convention: hash_md5` like so:
495
+
496
+
=== "YAML"
497
+
498
+
```yaml linenums="1"
499
+
physical_table_naming_convention: hash_md5
500
+
```
501
+
502
+
=== "Python"
503
+
504
+
```python linenums="1"
505
+
from sqlmesh.core.config import Config, ModelDefaultsConfig, TableNamingConvention
This has a downside that now it's much more difficult to determine which table corresponds to which model by just looking at the database with a SQL client. However, the table names now have a predictable length so there are no longer any surprises with identfiers exceeding the max length at the physical layer.
525
+
439
526
#### Environment view catalogs
440
527
441
528
By default, SQLMesh creates an environment view in the same [catalog](../concepts/glossary.md#catalog) as the physical table the view points to. The physical table's catalog is determined by either the catalog specified in the model name or the default catalog defined in the connection.
Copy file name to clipboardExpand all lines: docs/reference/configuration.md
+3-2Lines changed: 3 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -36,8 +36,9 @@ Configuration options for SQLMesh environment creation and promotion.
36
36
|`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 |
37
37
|`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 |
38
38
|`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 |
39
-
|`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 |
40
-
|`infer_python_dependencies`| Whether SQLMesh will statically analyze Python code to automatically infer Python package requirements. (Default: True) | boolean | N |
39
+
|`physical_table_naming_convention`| Sets which parts of the model name are included in the physical table names. Options are `schema_and_table` or `table_only` - [additional details](../guides/configuration.md#physical-table-naming-convention). (Default: `schema_and_table`) | string | N |
40
+
|`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 |
41
+
|`infer_python_dependencies`| Whether SQLMesh will statically analyze Python code to automatically infer Python package requirements. (Default: True) | boolean | N |
41
42
|`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 |
42
43
|`log_limit`| The default number of logs to keep (Default: `20`) | int | N |
model_defaults: Default values for model definitions.
107
107
physical_schema_mapping: A mapping from regular expressions to names of schemas in which physical tables for corresponding models will be placed.
108
108
environment_suffix_target: Indicates whether to append the environment name to the schema or table name.
109
+
physical_table_naming_convention: Indicates how tables should be named at the physical layer
109
110
gateway_managed_virtual_layer: Whether the models' views in the virtual layer are created by the model-specific gateway rather than the default gateway.
110
111
infer_python_dependencies: Whether to statically analyze Python code to automatically infer Python package requirements.
111
112
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.
0 commit comments