Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sqlmesh plan --restate-model requires model files to be present #3260

Open
giovannipcarvalho opened this issue Oct 16, 2024 · 3 comments
Open
Labels
Improvement Improves existing functionality

Comments

@giovannipcarvalho
Copy link
Contributor

Hi!

Since v0.119.0 sqlmesh run does not require any model definitions in the models/ to refresh model data.

While clearing some confusion I had about sqlmesh plan --restate-model's behavior, it was pointed out to me that it should only refresh data, but not update models' definitions (like a regular plan would).

So I expected that a restatement should also not require the definitions, if it only refreshes data. But when testing the behavior it does not seem to be the case.

repro

setup

$ uv venv && uv pip install sqlmesh && . .venv/bin/activate
$ sqlmesh --version
0.127.1

t.sh -- helper script

#!/usr/bin/env bash
function remove_definitions {
    rm -rf models seeds tests audits macros logs .cache
}

remove_definitions

rm -rf config.yaml db.db
sqlmesh init duckdb
sqlmesh plan --auto-apply >/dev/null

remove_definitions

I believe a restatement shouldn't require model definitions in order to only refresh data, similar to run.

$ ./t.sh && sqlmesh plan -r sqlmesh_example.full_model -s '' -e '' --auto-apply
Error: `('/tmp/sqlmesh-tmp',)` doesn't seem to have any models... cd into the proper directory or specify the path(s) with -p.

Defining a dummy full_model makes it work:

$ mkdir models && echo 'MODEL (name sqlmesh_example.full_model); select 1 as foo' > models/full_model.sql
$ sqlmesh plan -r sqlmesh_example.full_model -s '' -e '' --auto-apply
No differences when compared to `prod`
Models needing backfill (missing dates):
└── sqlmesh_example.full_model: 2024-10-15 - 2024-10-15
[...]
The target environment has been updated successfully

And the original model definition is not replaced by the dummy that was introduced, as expected:

$ duckdb -c 'select * from sqlmesh_example.full_model' db.db 
┌─────────┬────────────┐
│ item_id │ num_orders │
│  int32  │   int64    │
├─────────┼────────────┤
│       2 │          1 │
│       1 │          5 │
│       3 │          1 │
└─────────┴────────────┘

Am I misguided here?

Thanks in advance.


For completeness sake, to demonstrate that sqlmesh run behaves like this since v0.119:

$ uv pip install -U sqlmesh==0.118.0 && ./t.sh && sqlmesh run
[...]
Error: `('/tmp/sqlmesh-tmp',)` doesn't seem to have any models... cd into the proper directory or specify the path(s) with -p.
$ uv pip install -U sqlmesh==0.119.0 && ./t.sh && sqlmesh run
[...]
Run finished for environment 'prod'
@georgesittas
Copy link
Contributor

This does look like a bug, @izeigerman can you verify?

@izeigerman
Copy link
Member

Yes, restatements shouldn't require model files now that we purposefully ignore local changes when doing the restatement.

@izeigerman izeigerman added the Improvement Improves existing functionality label Oct 24, 2024
@hardeybisey
Copy link

@izeigerman can you assign this to me. Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Improvement Improves existing functionality
Projects
None yet
Development

No branches or pull requests

4 participants