Skip to content

Commit 3046555

Browse files
authored
Chore: update to docs to recommend using utf-8 (#2515)
* Chore: update to docs to recommend using utf-8 * PR feedback
1 parent 11697a1 commit 3046555

File tree

4 files changed

+17
-1
lines changed

4 files changed

+17
-1
lines changed

docs/concepts/models/overview.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Overview
22

3-
Models are comprised of metadata and queries that create tables and views, which can be used by other models or even outside of SQLMesh. They are defined in the `models/` directory of your SQLMesh project and live in `.sql` files.
3+
Models are made up of metadata and queries that create tables and views, which can be used by other models or even outside of SQLMesh. They are defined in the `models/` directory of your SQLMesh project and live in `.sql` files.
44

55
SQLMesh will automatically determine the relationships among and lineage of your models by parsing SQL, so you don't have to worry about manually configuring dependencies.
66

docs/concepts/models/seed_models.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,10 @@ MODEL (
6060

6161
This is useful when you want to keep all seed CSV files in a top-level directory such as `seeds/` but don't want to keep track of or manage a bunch of relative paths.
6262

63+
### Encoding
64+
65+
SQLMesh expects seed files to be encoded according to the [UTF-8](https://en.wikipedia.org/wiki/UTF-8) standard. Using a different encoding may lead to unexpected behavior.
66+
6367
## Example
6468

6569
In this example, we use the model definition from the previous section saved in the `models/national_holidays.sql` file of the SQLMesh project.

docs/concepts/models/sql_models.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,18 +53,21 @@ UNCACHE TABLE countries;
5353
```
5454

5555
### `MODEL` DDL
56+
5657
The `MODEL` DDL is used to specify metadata about the model such as its name, [kind](./model_kinds.md), owner, cron, and others. This should be the first statement in your SQL-based model's file.
5758

5859
Refer to `MODEL` [properties](./overview.md#properties) for the full list of allowed properties.
5960

6061
### Optional pre/post-statements
62+
6163
Optional pre/post-statements allow you to execute SQL commands before and after a model runs, respectively.
6264

6365
For example, post/post-statements might modify settings or create indexes. However, be careful not to run any statement that could conflict with the execution of another statement if the models run concurrently, such as creating a physical table.
6466

6567
Pre/post-statements are evaluated twice: when a model's table is created and when its query logic is evaluated. Since executing such statements more than once can have unintended side-effects, it is also possible to [conditionally execute](../macros/sqlmesh_macros.md#if) them depending on SQLMesh's [runtime stage](../macros/macro_variables.md#predefined-variables).
6668

6769
### The model query
70+
6871
The model must contain a standalone query, which can be a single `SELECT` expression, or multiple `SELECT` expressions combined with the `UNION`, `INTERSECT`, or `EXCEPT` operators. The result of this query will be used to populate the model's table or view.
6972

7073
## Python-based definition
@@ -113,6 +116,7 @@ The `@model` decorator is the Python equivalent of the `MODEL` DDL. In addition
113116
**Note:** All of the [metadata](./overview.md#properties) field names are the same as those in the `MODEL` DDL.
114117

115118
## Automatic dependencies
119+
116120
SQLMesh parses your SQL, so it understands what the code does and how it relates to other models. There is no need for you to manually specify dependencies to other models with special tags or commands.
117121

118122
For example, consider a model with this query:
@@ -131,21 +135,29 @@ External dependencies not defined in SQLMesh are also supported. SQLMesh can eit
131135
Although automatic dependency detection works most of the time, there may be specific cases for which you want to define dependencies manually. You can do so in the `MODEL` DDL with the [dependencies property](./overview.md#properties).
132136

133137
## Conventions
138+
134139
SQLMesh encourages explicitly specifying the data types of a model's columns through casting. This allows SQLMesh to understand the data types in your models, and it prevents incorrect type inference. SQLMesh supports the casting format `<column name>::<data type>` in models of any SQL dialect.
135140

136141
### Explicit SELECTs
142+
137143
Although `SELECT *` is convenient, it is dangerous because a model's results can change due to external factors (e.g., an upstream source adding or removing a column). In general, we encourage listing out every column you need or using [`create_external_models`](../../reference/cli.md#create_external_models) to capture the schema of an external data source.
138144

139145
If you select from an external source, `SELECT *` will prevent SQLMesh from performing some optimization steps and from determining upstream column-level lineage. Use an [`external` model kind](./model_kinds.md#external) to enable optimizations and upstream column-level lineage for external sources.
140146

147+
### Encoding
148+
149+
SQLMesh expects files containing SQL models to be encoded according to the [UTF-8](https://en.wikipedia.org/wiki/UTF-8) standard. Using a different encoding may lead to unexpected behavior.
150+
141151
## Transpilation
152+
142153
SQLMesh leverages [SQLGlot](https://github.com/tobymao/sqlglot) to parse and transpile SQL. Therefore, you can write your SQL in any supported dialect and transpile it into another supported dialect.
143154

144155
You can also use advanced syntax that may not be available in your engine of choice. For example, `x::int` is equivalent to `CAST(x as INT)`, but is only supported in some dialects. SQLGlot allows you to use this feature regardless of what engine you're using.
145156

146157
Additionally, you won't have to worry about minor formatting differences such as trailing commas, as SQLGlot will remove them at parse time.
147158

148159
## Macros
160+
149161
Although standard SQL is very powerful, complex data systems often require running SQL queries with dynamic components such as date filters. For example, you may want to change the date ranges in a `between` statement so that you can get the latest batch of data. SQLMesh provides these dates automatically through [macro variables](../macros/macro_variables.md).
150162

151163
Additionally, large queries can be difficult to read and maintain. In order to make queries more compact, SQLMesh supports a powerful [macro syntax](../macros/overview.md) as well as [Jinja](https://jinja.palletsprojects.com/en/3.1.x/), allowing you to write macros that make your SQL queries easier to manage.

examples/sushi/hooks/__init__.py

Whitespace-only changes.

0 commit comments

Comments
 (0)