Skip to content

Commit 15a9603

Browse files
authored
Merge branch 'main' into add_fabric_warehouse
2 parents 3a06c90 + 83137ff commit 15a9603

84 files changed

Lines changed: 3231 additions & 1440 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.circleci/continue_config.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,7 @@ workflows:
306306
- "3.10"
307307
- "3.11"
308308
- "3.12"
309+
- "3.13"
309310
- cicd_tests_windows
310311
- engine_tests_docker:
311312
name: engine_<< matrix.engine >>

.github/workflows/pr.yaml

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ jobs:
2626
- name: Run CI
2727
run: pnpm run ci
2828
test-vscode-e2e:
29-
runs-on: ubuntu-latest
29+
runs-on:
30+
labels: [ubuntu-2204-8]
3031
steps:
3132
- uses: actions/checkout@v4
3233
- uses: actions/setup-node@v4
@@ -41,22 +42,43 @@ jobs:
4142
uses: actions/setup-python@v5
4243
with:
4344
python-version: '3.12'
45+
- name: Cache pip dependencies
46+
uses: actions/cache@v4
47+
with:
48+
path: ~/.cache/pip
49+
key:
50+
${{ runner.os }}-pip-${{ hashFiles('**/requirements*.txt',
51+
'**/pyproject.toml', '**/setup.py') }}
52+
restore-keys: |
53+
${{ runner.os }}-pip-
54+
- name: Cache virtual environment
55+
uses: actions/cache@v4
56+
with:
57+
path: .venv
58+
key:
59+
${{ runner.os }}-venv-${{ hashFiles('**/requirements*.txt',
60+
'**/pyproject.toml', '**/setup.py') }}
61+
restore-keys: |
62+
${{ runner.os }}-venv-
4463
- name: Install python dependencies
4564
run: |
4665
python -m venv .venv
4766
source .venv/bin/activate
4867
make install-dev
49-
- name: Fetch VS Code
50-
working-directory: ./vscode/extension
51-
run: pnpm run fetch-vscode
52-
5368
- name: Install code-server
5469
run: curl -fsSL https://code-server.dev/install.sh | sh
5570
- name: Install Playwright browsers
5671
working-directory: ./vscode/extension
5772
run: pnpm exec playwright install
5873
- name: Run e2e tests
5974
working-directory: ./vscode/extension
75+
timeout-minutes: 90
6076
run: |
6177
source ../../.venv/bin/activate
62-
pnpm run test:e2e tests/stop.spec.ts
78+
pnpm run test:e2e
79+
- uses: actions/upload-artifact@v4
80+
if: ${{ !cancelled() }}
81+
with:
82+
name: playwright-report
83+
path: vscode/extension/playwright-report/
84+
retention-days: 30

.github/workflows/release_extension.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ jobs:
3232
with:
3333
node-version: '20'
3434
- name: Install pnpm
35-
uses: pnpm/action-setup@v2
35+
uses: pnpm/action-setup@v4
3636
with:
3737
version: 10
3838
- name: Install dependencies

.prettierignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ vscode/extension/out
2020
vscode/extension/src_react
2121
vscode/extension/tsconfig.tsbuildinfo
2222
vscode/extension/.vscode-test/
23+
vscode/extension/playwright-report/
24+
vscode/extension/test-results/
25+
vscode/extension/.test_setup
2326

2427
sqlmesh
2528
docs

docs/concepts/macros/macro_variables.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ Prefixes:
6868
Postfixes:
6969

7070
* dt - A python datetime object that converts into a native SQL `TIMESTAMP` (or SQL engine equivalent)
71+
* dtntz - A python datetime object that converts into a native SQL `TIMESTAMP WITHOUT TIME ZONE` (or SQL engine equivalent)
7172
* date - A python date object that converts into a native SQL `DATE`
7273
* ds - A date string with the format: '%Y-%m-%d'
7374
* ts - An ISO 8601 datetime formatted string: '%Y-%m-%d %H:%M:%S'
@@ -83,6 +84,11 @@ All predefined temporal macro variables:
8384
* @end_dt
8485
* @execution_dt
8586

87+
* dtntz
88+
* @start_dtntz
89+
* @end_dtntz
90+
* @execution_dtntz
91+
8692
* date
8793
* @start_date
8894
* @end_date

docs/concepts/models/model_kinds.md

Lines changed: 40 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -935,7 +935,13 @@ SQLMesh achieves this by adding a `valid_from` and `valid_to` column to your mod
935935

936936
Therefore, you can use these models to not only tell you what the latest value is for a given record but also what the values were anytime in the past. Note that maintaining this history does come at a cost of increased storage and compute and this may not be a good fit for sources that change frequently since the history could get very large.
937937

938-
**Note**: Partial data [restatement](../plans.md#restatement-plans) is not supported for this model kind, which means that the entire table will be recreated from scratch if restated. This may lead to data loss, so data restatement is disabled for models of this kind by default.
938+
**Note**: SCD Type 2 models support [restatements](../plans.md#restatement-plans) with specific limitations:
939+
940+
- **Full restatements**: The entire table will be recreated from scratch when no start date is specified
941+
- **Partial restatements**: You can specify a start date to restate data from a certain point onwards to the latest interval. The end date will always be set to the latest interval's end date, regardless of what end date you specify
942+
- **Partial sections**: Restatements of specific sections (discontinued ranges) of the table are not supported
943+
944+
Data restatement is disabled for models of this kind by default (`disable_restatement true`). To enable restatements, set `disable_restatement false` in your model configuration.
939945

940946
There are two ways to tracking changes: By Time (Recommended) or By Column.
941947

@@ -1283,11 +1289,11 @@ This is the most accurate representation of the menu based on the source data pr
12831289

12841290
### Processing Source Table with Historical Data
12851291

1286-
The most common case for SCD Type 2 is creating history for a table that it doesn't have it already.
1292+
The most common case for SCD Type 2 is creating history for a table that it doesn't have it already.
12871293
In the example of the restaurant menu, the menu just tells you what is offered right now, but you want to know what was offered over time.
12881294
In this case, the default setting of `None` for `batch_size` is the best option.
12891295

1290-
Another use case though is processing a source table that already has history in it.
1296+
Another use case though is processing a source table that already has history in it.
12911297
A common example of this is a "daily snapshot" table that is created by a source system that takes a snapshot of the data at the end of each day.
12921298
If your source table has historical records, like a "daily snapshot" table, then set `batch_size` to `1` to process each interval (each day if a `@daily` cron) in sequential order.
12931299
That way the historical records will be properly captured in the SCD Type 2 table.
@@ -1433,11 +1439,14 @@ GROUP BY
14331439
id
14341440
```
14351441

1436-
### Reset SCD Type 2 Model (clearing history)
1442+
### SCD Type 2 Restatements
14371443

14381444
SCD Type 2 models are designed by default to protect the data that has been captured because it is not possible to recreate the history once it has been lost.
14391445
However, there are cases where you may want to clear the history and start fresh.
1440-
For this use use case you will want to start by setting `disable_restatement` to `false` in the model definition.
1446+
1447+
#### Enabling Restatements
1448+
1449+
To enable restatements for an SCD Type 2 model, set `disable_restatement` to `false` in the model definition:
14411450

14421451
```sql linenums="1" hl_lines="5"
14431452
MODEL (
@@ -1449,16 +1458,39 @@ MODEL (
14491458
);
14501459
```
14511460

1452-
Plan/apply this change to production.
1453-
Then you will want to [restate the model](../plans.md#restatement-plans).
1461+
#### Full Restatements (Clearing All History)
1462+
1463+
To clear all history and recreate the entire table from scratch:
14541464

14551465
```bash
14561466
sqlmesh plan --restate-model db.menu_items
14571467
```
14581468

14591469
!!! warning
14601470

1461-
This will remove the historical data on the model which in most situations cannot be recovered.
1471+
This will remove **all** historical data on the model which in most situations cannot be recovered.
1472+
1473+
#### Partial Restatements (From a Specific Date)
1474+
1475+
You can restate data from a specific start date onwards. This will:
1476+
- Delete all records with `valid_from >= start_date`
1477+
- Reprocess the data from the start date to the latest interval
1478+
1479+
```bash
1480+
sqlmesh plan --restate-model db.menu_items --start "2023-01-15"
1481+
```
1482+
1483+
!!! note
1484+
1485+
If you specify an end date for SCD Type 2 restatements, it will be ignored and automatically set to the latest interval's end date.
1486+
1487+
```bash
1488+
# This end date will be ignored and set to the latest interval
1489+
sqlmesh plan --restate-model db.menu_items --start "2023-01-15" --end "2023-01-20"
1490+
```
1491+
1492+
1493+
#### Re-enabling Protection
14621494

14631495
Once complete you will want to remove `disable_restatement` on the model definition which will set it back to `true` and prevent accidental data loss.
14641496

docs/guides/configuration.md

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,52 @@ All software runs within a system environment that stores information as "enviro
9898

9999
SQLMesh can access environment variables during configuration, which enables approaches like storing passwords/secrets outside the configuration file and changing configuration parameters dynamically based on which user is running SQLMesh.
100100

101-
You can use environment variables in two ways: specifying them in the configuration file or creating properly named variables to override configuration file values.
101+
You can specify environment variables in the configuration file or by storing them in a `.env` file.
102+
103+
### .env files
104+
105+
SQLMesh automatically loads environment variables from a `.env` file in your project directory. This provides a convenient way to manage environment variables without having to set them in your shell.
106+
107+
Create a `.env` file in your project root with key-value pairs:
108+
109+
```bash
110+
# .env file
111+
SNOWFLAKE_PW=my_secret_password
112+
S3_BUCKET=s3://my-data-bucket/warehouse
113+
DATABASE_URL=postgresql://user:pass@localhost/db
114+
115+
# Override specific SQLMesh configuration values
116+
SQLMESH__DEFAULT_GATEWAY=production
117+
SQLMESH__MODEL_DEFAULTS__DIALECT=snowflake
118+
```
119+
120+
See the [overrides](#overrides) section for a detailed explanation of how these are defined.
121+
122+
The rest of the `.env` file variables can be used in your configuration files with `{{ env_var('VARIABLE_NAME') }}` syntax in YAML or accessed via `os.environ['VARIABLE_NAME']` in Python.
123+
124+
#### Custom dot env file location and name
125+
126+
By default, SQLMesh loads `.env` files from each project directory. However, you can specify a custom path using the `--dotenv` CLI flag directly when running a command:
127+
128+
```bash
129+
sqlmesh --dotenv /path/to/custom/.env plan
130+
```
131+
132+
!!! note
133+
The `--dotenv` flag is a global option and must be placed **before** the subcommand (e.g. `plan`, `run`), not after.
134+
135+
Alternatively, you can export the `SQLMESH_DOTENV_PATH` environment variable once, to persist a custom path across all subsequent commands in your shell session:
136+
137+
```bash
138+
export SQLMESH_DOTENV_PATH=/path/to/custom/.custom_env
139+
sqlmesh plan
140+
sqlmesh run
141+
```
142+
143+
**Important considerations:**
144+
- Add `.env` to your `.gitignore` file to avoid committing sensitive information
145+
- SQLMesh will only load the `.env` file if it exists in the project directory (unless a custom path is specified)
146+
- When using a custom path, that specific file takes precedence over any `.env` file in the project directory.
102147

103148
### Configuration file
104149

docs/guides/projects.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,18 +27,18 @@ To create a project from the command line, follow these steps:
2727
1. To scaffold a project, it is recommended that you use a python virtual environment by running the following commands:
2828
2929
```bash
30-
python -m venv .env
30+
python -m venv .venv
3131
```
3232
3333
```bash
34-
source .env/bin/activate
34+
source .venv/bin/activate
3535
```
3636
3737
```bash
3838
pip install sqlmesh
3939
```
4040
41-
**Note:** When using a python virtual environment, you must ensure that it is activated first. You should see `(.env)` in your command line; if you don't, run `source .env/bin/activate` from your project directory to activate your environment.
41+
**Note:** When using a python virtual environment, you must ensure that it is activated first. You should see `(.venv)` in your command line; if you don't, run `source .venv/bin/activate` from your project directory to activate your environment.
4242

4343
1. Once you have activated your environment, run the following command and SQLMesh will build out your project:
4444

docs/guides/ui.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ For development work, we recommend using the SQLMesh UI alongside an IDE. The UI
2424

2525
Before beginning, ensure that you meet all the [prerequisites](../prerequisites.md) for using SQLMesh. The SQLMesh browser UI requires additional Python libraries not included in the base SQLMesh installation.
2626

27-
To use the UI, install SQLMesh with the `web` add-on. First, if using a python virtual environment, ensure it's activated by running `source .env/bin/activate` command from the folder used during [installation](../installation.md).
27+
To use the UI, install SQLMesh with the `web` add-on. First, if using a python virtual environment, ensure it's activated by running `source .venv/bin/activate` command from the folder used during [installation](../installation.md).
2828

2929
Next, install the UI with `pip`:
3030

docs/installation.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@ It is recommended, but not required, that you use a python virtual environment w
88

99
First, create the virtual environment:
1010
```bash
11-
python -m venv .env
11+
python -m venv .venv
1212
```
1313

1414
Then activate it:
1515
```bash
16-
source .env/bin/activate
16+
source .venv/bin/activate
1717
```
1818

1919
## Install SQLMesh core

0 commit comments

Comments
 (0)