-
Notifications
You must be signed in to change notification settings - Fork 231
Feat!: Add support for virtual statements to be executed post update #3524
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
Conversation
f57f88e
to
f012e96
Compare
Can we please make sure this feature is documented before we merge. |
10006db
to
14d1f49
Compare
14d1f49
to
46bb623
Compare
46bb623
to
d225eeb
Compare
d225eeb
to
a2b8955
Compare
7d1e30d
to
6343569
Compare
3e4492c
to
a4d4de6
Compare
sqlmesh/core/snapshot/evaluator.py
Outdated
@@ -853,7 +859,18 @@ def _promote_snapshot( | |||
view_name=view_name, | |||
model=snapshot.model, | |||
environment=environment_naming_info.name, | |||
deployability_index=deployability_index, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we still need to pass deployability_index here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh right we don't will remove this
default_catalog: t.Optional[str] = None, | ||
dialect: t.Optional[str] = None, | ||
) -> t.Dict[str, str]: | ||
return { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[Nit] I guess we can return empty dict here if the environment is prod
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried it, but it didn't work since it led to the model names been mapped to the physical table names. This is because in resolve tables without this dict or an empty dict: _to_table_mapping
is used to create the mapping:
sqlmesh/sqlmesh/core/renderer.py
Line 281 in c8fc94e
**self._to_table_mapping(snapshots.values(), deployability_index), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks great, thank you!
a4d4de6
to
ac4b4f5
Compare
This update introduces statements that are executed after a virtual update. These can be used for example to grant privileges on views of the virtual layer.
These expressions should be defined within a
ON_VIRTUAL_UPDATE_BEGIN; ...; ON_VIRTUAL_UPDATE_END;
block. For example:Jinja expressions are also supported within this block by properly nesting the Jinja block as shown in the example above.
In these statements table resolution occurs at the virtual level, meaning that qualified view names (including
@this_model
) are used instead of the physical table names. For example, when running the plan in an environment nameddev
, thedb.customers
as well asthis_model
would resolve todb__dev.customers
rather than the physical table.For python models these statements are defined in the
@model
decorator: