-
Notifications
You must be signed in to change notification settings - Fork 55
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
Incorrect Schema Used When Renaming Materialized Views #366
Comments
There is a workaround we have found which is to use this config
A Regarding the |
relevant sections of dbt-trino code
We can clearly see in that code, on line 16, that it ends up trying to rename the existing MV to a backup version, but it drops the schema from the backup version's name - It ends up creating the backup in whatever the default schema of the connection is, instead of the schema it should be in. However, in dbt-core, when it's setting up the MV, it drops the MV backup if it already exists using the actual name it should be, including schema, at https://github.com/dbt-labs/dbt-core/blob/v1.6.6/core/dbt/include/global_project/macros/materializations/models/materialized_view/materialized_view.sql#L32-L34 . So, what happens is dbt checks for the backup MV to drop if it already exists, doesn't find it, and then dbt-trino tries to rename the existing MV to the backup version but in the wrong schema (that's different from where dbt-core just checked), causing this error. Overall seems like a clear bug in |
This was a team effort, so thanks to Ben and Dalibor on my team for discovering the fixes laid out here. |
@wjhrdy Thanks for reporting this! All of your investigation is correct, and indeed, it is a bug. |
Expected behavior
When renaming a materialized view to a backup version, the schema of the original materialized view should be retained. The backup version should be created in the same schema as the original materialized view.
Actual behavior
Currently, when renaming a materialized view to a backup version, the schema of the backup version is dropped. This results in the backup version being created in the default schema of the connection, instead of the schema of the original materialized view. This discrepancy causes an error when dbt checks for the backup materialized view to drop if it already exists, as it checks in the original schema, not finding the backup version that was created in the default schema.
Steps To Reproduce
Log output/Screenshots
the
default_schema.materialized_view_dbt_backup
should look something likedefault_schema_intermediate.materialized_view_dbt_backup
Operating System
macOS 13.4 (22F66)
dbt version
Core: - installed: 1.6.6 - latest: 1.6.6 - Up to date! Plugins: - trino: 1.6.2 - Up to date!
Trino Server version
423-e.1
Python version
Python 3.9.16
Are you willing to submit PR?
The text was updated successfully, but these errors were encountered: