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/concepts/models/external_models.md
+13-13Lines changed: 13 additions & 13 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -10,15 +10,15 @@ SQLMesh stores external tables' column information as `EXTERNAL` models.
10
10
11
11
`EXTERNAL` models consist solely of an external table's column information, so there is no query for SQLMesh to run.
12
12
13
-
SQLMesh has no information about the data contained in the table represented by an `EXTERNAL` model. The table could be altered or have all its data deleted, and SQLMesh will not detect it. All SQLMesh knows about the table is that it contains the columns specified in the `EXTERNAL` model's `schema.yaml`file (more information below).
13
+
SQLMesh has no information about the data contained in the table represented by an `EXTERNAL` model. The table could be altered or have all its data deleted, and SQLMesh will not detect it. All SQLMesh knows about the table is that it contains the columns specified in the `EXTERNAL` model's file (more information below).
14
14
15
15
SQLMesh will not take any actions based on an `EXTERNAL` model - its actions are solely determined by the model whose query selects from the `EXTERNAL` model.
16
16
17
17
The querying model's [`kind`](./model_kinds.md), [`cron`](./overview.md#cron), and previously loaded time intervals determine when SQLMesh will query the `EXTERNAL` model.
18
18
19
19
## Generating an external models schema file
20
20
21
-
External models can be defined in the `schema.yaml` file in the SQLMesh project's root folder.
21
+
External models can be defined in the `external_models.yaml` file in the SQLMesh project's root folder. The alternative name for this file is `schema.yaml`.
22
22
23
23
You can create this file by either writing the YAML by hand or allowing SQLMesh to fetch information about external tables with the `create_external_models` CLI command.
24
24
@@ -38,13 +38,13 @@ FROM
38
38
39
39
The following sections demonstrate how to create an external model containing `external_db.external_table`'s column information.
40
40
41
-
All of a SQLMesh project's external models are defined in a single `schema.yaml` file, so the files created below might also include column information for other external models.
41
+
All of a SQLMesh project's external models are defined in a single `external_models.yaml` file, so the files created below might also include column information for other external models.
42
42
43
43
Alternatively, additional external models can also be defined in the [external_models/](#using-the-external_models-directory) folder.
44
44
45
45
### Writing YAML by hand
46
46
47
-
This example demonstrates the structure of a `schema.yaml` file:
47
+
This example demonstrates the structure of a `external_models.yaml` file:
48
48
49
49
```yaml
50
50
- name: external_db.external_table
@@ -65,9 +65,9 @@ The file can be constructed by hand using a standard text editor or IDE.
65
65
66
66
### Using CLI
67
67
68
-
Instead of creating the `schema.yaml` file manually, SQLMesh can generate it for you with the [create_external_models](../../reference/cli.md#create_external_models) CLI command.
68
+
Instead of creating the `external_models.yaml` file manually, SQLMesh can generate it for you with the [create_external_models](../../reference/cli.md#create_external_models) CLI command.
69
69
70
-
The command identifies all external tables referenced in your SQLMesh project, fetches their column information from the SQL engine's metadata, and then stores the information in the `schema.yaml` file.
70
+
The command identifies all external tables referenced in your SQLMesh project, fetches their column information from the SQL engine's metadata, and then stores the information in the `external_models.yaml` file.
71
71
72
72
If SQLMesh does not have access to an external table's metadata, the table will be omitted from the file and SQLMesh will issue a warning.
73
73
@@ -77,18 +77,18 @@ If SQLMesh does not have access to an external table's metadata, the table will
77
77
78
78
Sometimes, SQLMesh cannot infer the structure of a model and you need to add it manually.
79
79
80
-
However, since `sqlmesh create_external_models` replaces the `schema.yaml` file, any manual changes you made to that file will be overwritten.
80
+
However, since `sqlmesh create_external_models` replaces the `external_models.yaml` file, any manual changes you made to that file will be overwritten.
81
81
82
82
The solution is to create the manual model definition files in the `external_models/` directory, like so:
83
83
84
84
```
85
-
schema.yaml
86
-
external_models/another_schema.yaml
87
-
external_models/yet_another_schema.yaml
85
+
external_models.yaml
86
+
external_models/more_external_models.yaml
87
+
external_models/even_more_external_models.yaml
88
88
```
89
89
90
-
Files in the `external_models` directory must be `.yaml` files that follow the same structure as the `schema.yaml` file.
90
+
Files in the `external_models` directory must be `.yaml` files that follow the same structure as the `external_models.yaml` file.
91
91
92
-
When SQLMesh loads the definitions, it will first load the models defined in `schema.yaml` followed by any models it can find in `external_models/*.yaml`.
92
+
When SQLMesh loads the definitions, it will first load the models defined in `external_models.yaml` (or `schema.yaml`) and any models found in `external_models/*.yaml`.
93
93
94
-
Therefore, you can use `sqlmesh create_external_models` to manage the `schema.yaml` file and then put any models that need to be defined manually inside the `external_models/` directory.
94
+
Therefore, you can use `sqlmesh create_external_models` to manage the `external_models.yaml` file and then put any models that need to be defined manually inside the `external_models/` directory.
Copy file name to clipboardExpand all lines: docs/concepts/tests.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
@@ -474,7 +474,7 @@ It's not always possible to correctly interpret certain values in a unit test wi
474
474
475
475
To avoid this ambiguity, SQLMesh needs to know the columns' types. By default, it will try to infer these types based on the model definitions, but they can also be explicitly specified:
476
476
477
-
- in the [`schema.yaml`](models/external_models.md#generating-an-external-models-schema-file) file (for external models)
477
+
- in the [`external_models.yaml`](models/external_models.md#generating-an-external-models-schema-file) file (for external models)
478
478
- using the [`columns`](models/overview.md#columns) model property
479
479
- using the [`columns`](#creating_tests) attribute of the unit test
Copy file name to clipboardExpand all lines: docs/guides/table_migration.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
@@ -39,7 +39,7 @@ Consider an existing table named `my_schema.existing_table`. Migrating this tabl
39
39
40
40
1. Ensure `my_schema.existing_table` is up to date (has ingested all available source data)
41
41
2. Rename `my_schema.existing_table` to any other name, such as `my_schema.existing_table_historical`
42
-
- Optionally, enable column-level lineage for the table by making it an [`EXTERNAL` model](../concepts/models/model_kinds.md#external) and adding it to the project's `schema.yaml` file
42
+
- Optionally, enable column-level lineage for the table by making it an [`EXTERNAL` model](../concepts/models/model_kinds.md#external) and adding it to the project's `external_models.yaml` file
43
43
3. Create a new incremental staging model named `my_schema.existing_table_staging` (see below for code)
44
44
4. Create a new [`VIEW` model](../concepts/models/model_kinds.md#view) named `my_schema.existing_table` (see below for code)
45
45
5. Run `sqlmesh plan` to create and backfill the models
0 commit comments