-
Notifications
You must be signed in to change notification settings - Fork 174
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
Feat!: Add support for virtual statements to be executed post update #3524
base: main
Are you sure you want to change the base?
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
sqlmesh/core/snapshot/evaluator.py
Outdated
view_name, | ||
exp.select("*").from_(table_name, dialect=self.adapter.dialect), | ||
table_description=model.description if is_prod else None, | ||
column_descriptions=model.column_descriptions if is_prod else None, | ||
view_properties=model.virtual_properties, | ||
) | ||
if on_virtual_update := model.on_virtual_update: | ||
adapter.execute( | ||
model._render_statements(on_virtual_update, engine_adapter=adapter, **kwargs) |
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.
Let's not call private methods here. What you had previously (render_on_virtual_update
) was great.
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.
Also I don't think kwargs
contains anything meaningful here. This is mostly for future expansions, since this interface is public. No need to pass in into renderer I don't think
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.
Right changing it to use a public method instead similar to pre/post statements
Regarding the kwargs
I am passing the table mapping of qualified view names, which is then propagated down to render
and used here:
sqlmesh/sqlmesh/core/renderer.py
Line 382 in c1d117e
table_mapping=table_mapping, |
so it is needed to resolve model names to their corresponding
view
names of the current environment, so I'm not sure without passing them how I could do this
3e4492c
to
a4d4de6
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: