-
Notifications
You must be signed in to change notification settings - Fork 102
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
Support for changing database in model configuration #126
Conversation
@swanderz Why circleci run only unit test? |
not sure it was saying "unauthorized". I was able to manually re-run the checks and they are passing now. but wanna take a look at this list and see if some might apply to you? You have a CircleCI account right? |
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.
The CircleCI tests are passing for Azure SQL, but I'm think I'm going to test this out over the next few days.
{% macro sqlserver__create_view_exec(relation, sql) -%} | ||
{%- set temp_view_sql = sql.replace("'", "''") -%} | ||
execute('create view {{ relation.include(database=False) }} as | ||
{{ temp_view_sql }} | ||
'); | ||
{% endmacro %} | ||
|
||
|
||
{% macro sqlserver__create_view_as(relation, sql) -%} | ||
create view {{ relation.schema }}.{{ relation.identifier }} as | ||
{{ sql }} | ||
use [{{ relation.database }}]; | ||
{{ sqlserver__create_view_exec(relation, sql) }} | ||
{% endmacro %} |
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.
@semcha was the reason for this to make the macro run in a single transaction?
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.
What is your suggestion? :)
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 think my suggestion would be:
{% macro sqlserver__create_view_as(relation, sql) -%}
use [{{ relation.database }}];
create view {{ relation.include(database=false) }} as
{{ sql }}
{% endmacro %}
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.
@swanderz That way you get an error 'CREATE VIEW' must be the first statement in a query batch.
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.
@semcha have you tried running a dbt project after installing the adapter from this branch? I'd be interested if it works as we hope.
@swanderz Yep, it's currently running on my production server |
ok cool. so you're enabled in the short-term then. It's on my plate to see if this plays nicely with dbt-synapse. I hope to have time this week to do so. Thanks for all your work on this so far @semcha! this is the number one requested feature |
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.
Hi, This is all ok with me! @swanderz , do you have questions if this will work with Synapse to handle before merging?
yeah this is the last piece. I should have time to check in the next few days |
Thank you @semcha for this PR! I totally dropped the ball on this. I just experienced a |
Hi, could someone go ahead and merge this? :) |
Hey @panasenco we definitely want to merge this, but I need to test these changes with dbt-synapse which I haven't had the time to do yet. I promise to do it this week sometime. In the meantime, you can use this branch by installing this branch from GitHub or by cloning it locally and calling |
Yeah, I've been doing that, so no worries. :) |
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.
@semcha, I inititally made microsoft/dbt-synapse#49 to prove to you that this PR, won't work only to realize that only a few changes would be necessary!
@mikaelene, this PR is ready to merge, provided you're okay with releasing a v0.19.1
instead of a v0.19.0.3
!
Just ran into this myself, wasted a bunch of time on it. I should have checked this PR first. Thanks for the work here! |
I'll merge later today. @mikaelene will have to publish a release to PyPi though. |
Smoke test. One of my source tables isn't populated (I'd expect my staging model to fail) , the model looks like this
DBT reports this as running successfully after updating the macro. Even though my raw data doesn't exist. Looking at the dbt log and running the generated sql manually the command fails with something like this
|
Just to be clear, this pull request makes the code better than it was before so I'd say go ahead! Everything works on my end, it's just an error caused by EXEC |
* Support for changing database in model configuration * Bumbed version * Update dbt/include/sqlserver/macros/adapters.sql * Removed unnecessary check * drop redundancy * 3-part versions from now on * capitals as style guide * document * typo * style: capitalized function words Co-authored-by: Anders <swanson.anders@gmail.com>
I'm running into problems that are similar to visch's.
To be clear, I think it's Microsoft's fault, not yours! ;) All the best |
Yeah it's a problem. If you could put a test case together for them on #135 I think it would help get to the bottom of it. I haven't had the time to prove myself :D |
Fixes #110.