Skip to content

Commit 9fc9f20

Browse files
committed
Fix: Small improvements to the doc page for external models
1 parent 995926d commit 9fc9f20

File tree

1 file changed

+13
-23
lines changed

1 file changed

+13
-23
lines changed
Lines changed: 13 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
# External models
2-
Some SQLMesh models query "external" tables that were created by code unavailable to SQLMesh. External models are a special model kind used to store metadata about those external tables.
2+
Models may reference "external" tables that have been created outside SQLMesh. These external tables are captured in SQLMesh as models with a unique "external" kind. Each external model retains metadata about a table it represents.
33

4-
External models allow SQLMesh to provide column-level lineage and data type information for external tables queried with SELECT *.
4+
This metadata allows SQLMesh to provide column-level lineage and data type information for models that reference external tables.
55

66
## Generating external models schema
7-
External models consist of an external table's schema information stored in the `schema.yaml` file in the SQLMesh project's root directory.
7+
External models are defined in the `schema.yaml` file in the SQLMesh project's root folder.
88

9-
You can add schema information to the file by either (i) writing the YAML by hand or (ii) allowing SQLMesh to query the external table and add the information itself with the create_external_models CLI command.
9+
You can create this file by either (i) allowing SQLMesh to fetch information about external tables with the `create_external_models` CLI command or (ii) writing the YAML by hand.
1010

11-
Consider this example FULL model that queries an external table external_db.external_table:
11+
Consider this example model that queries an external table `external_db.external_table`:
1212

1313
```sql
1414
MODEL (
@@ -22,37 +22,27 @@ FROM
2222
external_db.external_table;
2323
```
2424

25-
The following sections demonstrate how to create an external model containing metadata about external_db.external_table, which contains columns column_a and column_b.
25+
The following sections demonstrate how to create an external model containing metadata about `external_db.external_table`, which contains columns `column_a` and `column_b`.
2626

27-
## Writing YAML by hand
28-
This example demonstrates how the schema.yaml file should be formatted.
27+
### Using CLI
28+
Instead of creating the `schema.yaml` file manually, SQLMesh can generate it for you. The [create_external_models](../../../reference/cli#create_external_models) CLI command does exactly this.
2929

30-
```yaml
31-
- name: external_db.external_table
32-
description: An external table
33-
columns:
34-
column_a: int
35-
column_b: text
36-
```
30+
The command locates all external tables referenced in your SQLMesh project, fetches their schemas (column names and types), and then stores them in the `schema.yaml` file.
3731

38-
All the external models in a SQLMesh project are stored in one schema.yaml file. The file might look like this with an additional external model:
32+
### Writing YAML by hand
33+
The following example demonstrates a typical content of the `schema.yaml` file:
3934

4035
```yaml
4136
- name: external_db.external_table
4237
description: An external table
4338
columns:
4439
column_a: int
4540
column_b: text
46-
- name: external_db.external_table_2
41+
- name: external_db.some_other_external_table
4742
description: Another external table
4843
columns:
4944
column_c: bool
5045
column_d: float
5146
```
5247
53-
### Using the create_external_models CLI command
54-
Instead of writing the external model YAML by hand, SQLMesh can create it for you with the [create_external_models](../../../reference/cli#create_external_models) CLI command.
55-
56-
The command locates all external tables queried in your SQLMesh project, executes the queries, and infers the tables' column names and types from the results.
57-
58-
It then writes that information to the schema.yaml file.
48+
All the external models in a SQLMesh project are stored in a single `schema.yaml` file.

0 commit comments

Comments
 (0)