-
Notifications
You must be signed in to change notification settings - Fork 177
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
[Feature] force correct 'use' when deploying #1051
Comments
@AartBluestoke Is the idea that dbt would, before a model's materialization, always call This could happen as a
But I believe the real solution is for dbt-snowflake to always use fully qualified names. I haven't seen this come up as an issue at all, outside the specific context of dynamic tables, as reflected in this bug (of which #1017 and #1047 are both duplicates): I'd rather just fix that specific bug. But please let me know if there's something I'm missing! |
@jtcohen6 i'm (from the one dbt project) deploying to multiple databases and schemas, and i've had to use the pre-hook to allow some queries to work. IMO any code that works without a databases or schema override config should continue to work when one is set - and this is currently not true, but that use statement to run the queries from the context of the requested database and schema would reduce the friction here. I'm targeting databases dev_landing and dev_datamart - the 'dev' prefix is parameterised with the current target. with some models in one, some in the other. I don't want to use fully qualified names in my views, etc ... (specifically, i don't want the database component, due to wanting code reusability between dev, test, and prod). |
@AartBluestoke Thanks for the reply - I have a few more questions:
Which queries have these been? As I said above, my impression is that this is only an issue for dynamic tables right now (due to #1031), because we should using fully qualified names everywhere else.
Is there a reason why dbt's environment handling for |
re "are you putting raw identifier names (schema.identifier) directly into your code?" -- no
Which works until you split some things between landing and datamart, and everything you put to datamart fails to release because the 'use' context is still landing, and it doesn't find the datamart objects to connect to. To work around this i have several places where i set 'use' in this my codebase |
I also have a custom snowflake materialiser that turns
into
note the difference between the queries in the top and bottom - we create selecting the reff, the task reads from the stream we created on the reff, and also includes the extra where clause to guard against duplicates. |
Is this your first time submitting a feature request?
Describe the feature
snowflake when deploying models that target other schemas or database, doesn't prefix its command with 'USE' so commands can executed from random contexts.
eg #1047 would not be an issue if the rename statement was issued from the context of useing the database and schema of the target model
#1017 also shows an error with 'Cannot perform CREATE TABLE. This session does not have a current schema. Call 'USE SCHEMA', or use a qualified name.'
Describe alternatives you've considered
i have a partially mitagated this with
+pre_hook: "USE {{target.name}}_{{ target.database }};"
Who will this benefit?
anyone who writes a view, or has code execute, and expects the code to be run from the context of the model
(create view statements with hard coded targets can have funny outcomes if executed from the wrong context)
Are you interested in contributing this feature?
No response
Anything else?
this should take into account model specific custom database and schema so that when a model is deployed to a unexpected location there are no surprises.
The text was updated successfully, but these errors were encountered: