-
Notifications
You must be signed in to change notification settings - Fork 98
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
Overriding the database in the dbt_project file does not work #59
Comments
interesting. i'm going to poke around with this and see what I can find out. |
Great! Thanks @swanderz. Is there any extra information I can provide to help you? |
Can call My thinking is that it has to do with this dbt-labs/dbt-core#1695, specifically the |
It's omitting the database name in the query. And when connecting, it uses the incorrect one (from profile instead of project). The SQL Query that loads the data:
|
I think the problem is in this part, rather than the generation of the queries: It should have connected to the ProductsModels database instead. |
def helpful. now i'm thinking it has to do with the
|
I'm all for an adventure! :) I added a file called sqlserver_create_view_as.sql in my macros folder with this as content:
But I have the impression it's not using it at all, because it's not logging the "THIS IS A TEST" anywhere. |
I now also tried it with two underscores in the filename behind sqlserver, and with one underscore in the macro function name, but all permutations those do not seem to work. |
ok. try renaming the macro to just |
Nope, doesn't work. |
Ah, sorry... I changed the materialization to table so it's obviously using sqlserver__create_table_as now. |
Ok so now you add a new macro called |
Adding USE {{ relation.database }}; seems to do the trick! I'm going to test it a bit more. |
It really helps to know that I can just override any macro from the adapter in the macros folder :) Thank you very much! |
Creating a new table when none exists works. But if the table already exists, it doesn't work. My first hunch was to look at the query that does the rename, but somehow my new definition of the rename_relation doesn't come through. I tried overriding both sqlserver__rename_relation and rename_relation. The error I get: 2020-11-19 20:19:23.209382 (Thread-1): On model.cm_datawarehouse.ProductsModels_Metrics: EXEC sp_rename 'ProductsModels.ProductsModels_Metrics__dbt_tmp', 'Metrics' |
welcome to the world of dbt adapter development and thanks for looking into this! At this point you're well on the way to your first PR. Feel free to do the macro over-riding for the short term, but this guide will guide you in how to make changes for a PR. As for the the rename thing you mention above, looks like it has something to do with the |
I don't know.. I got it working but the change seems odd. It's working if I drop the table/view just before the rename:
Also, fun fact, this query does not get logged into dbt.log even though I 'm pretty sure it gets executed. |
I think this is the issue here. The current macro assumes you are connected to the database you want to build the view in. Thus leaving out the database identifier. Actually SQL Server doesn't allow you to specify the database to build it into. You have to be in the right data base. I think this issue will be quite difficult to solve. dbt is reusing connections so there would be a risk of executing sql in the wrong database for the models you want in the database in the profile. Maybe we can add a |
Hi All, Thought I would drop a line here. I am also experiencing this problem. I followed the suggested fix in PR #126, installing dbt via cloning the branch from PR #126 . But I am still getting the same issue. I pasted the log below. In this case I am looking for the table I am working on SQL Server 2017
|
Hi Again, I seemed to have resolved the situation. I ran the compiled code directly in SQL Server, it gave me an error message that wasn't being surfaced in DBT. Basically there was a UDF I was referencing in the query (which I actually sanitized from the log posted above), the UDF is defined in the Default_DB, but I wasn't referencing it with the full location (ie I was only referring to schema.udf_name, not db.schema.udf_name), and either the error was causing the query to fail and write in the wrong location, or the ambiguous reference was somehow changing the destination back to the Default_DB. |
fixed by: #126! |
When I override the database to something different than the database configured in the profile, the CLI says it's going to built into the override database, but it's executed on the profile database.
Example profiles.xml:
example dbt_project.yml:
When ran, the CLI says "created view model ProductsModels.ProductsModels.Metrics..." but in reality it's created in Test.ProductsModels.Metrics
The text was updated successfully, but these errors were encountered: