-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Added support for BigQuery relation renaming #2521
Added support for BigQuery relation renaming #2521
Conversation
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.
Hey @azhard, thanks for contributing! This looks great, I have some minor feedback on ordering and some extra tests but this seems good.
Also, could you please add an integration test of some sort? The 054_adapter_methods test folder is probably appropriate. I'd hate to have this regress.
raise dbt.exceptions.NotImplementedException( | ||
'`rename_relation` is not implemented for this adapter!' | ||
) | ||
self.cache_renamed(from_relation, to_relation) |
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.
Can you move this down to just before the copy/delete calls? I think we want to avoid updating the cache until we're just about to do it, if possible.
from_relation.schema, | ||
from_relation.identifier, | ||
conn) | ||
from_table = client.get_table(from_table_ref) |
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.
Should this also ensure that from_relation.type
and to_relation.type
are the same type? And that to_relation.type
is not RelationType.View
?
Thanks for the feedback @beckjake. For the integration test, can you give me some more guidance on what exactly I should be testing / how. So for example am I testing that the rename functionality works across all adapters and if that's correct, how do I "confirm" that a rename took place? Or alternatively, am I testing the BigQuery specific rename (eg. copy and delete happen, doesn't work on views, etc.) If that's the case, I see similar testing done in |
You can just test bigquery for this, since that's all you've added! Here's a test I imagined:
Does that seem reasonable? |
Basically, I don't care how relations are renamed, but in my ideal world if bigquery offered "alter table rename ..." and we switched to using that, we'd probably want the test to still work. |
Yeah that makes a ton of sense to me, I'll look into adding that |
{%- set from_relation = adapter.get_relation(database=target.database, schema=target.schema, identifier=from_name) -%} | ||
{%- set to_relation = adapter.get_relation(database=target.database, schema=target.schema, identifier=to_name) -%} |
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 this needs to use api.Relation.create(database=target.database, schema=target.schema, identifier=from_name, type=RelationType.View)
rather than adapter.get_relation()
, because if the relation doesn't exist yet, the value will be None
.
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.
Oh good call, except I'm guessing you meant type = Table instead of View as the view rename isn't currently supported
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.
Oh, yes, that's exactly what I meant! I think it's actually got to be just the string 'table'
- RelationType
isn't available in macros.
Oh, I didn't understand what was going wrong with the postgres tests before, but now I realize. I think you'll need to put this new model/schema.yml into a new folder (maybe
|
@beckjake updated and 🤞 hopefully it should work now. I also updated Let me know if you'd rather I didn't make these changes or if there's a reason they're written like that and I can revert them. |
That all sounds great to me, thank you. I've kicked off the tests and we'll get this merged in for 0.18.0 once the tests pass. I don't really ever use the Makefile, so thank you for fixing that especially! |
Any idea why the CI is failing? I don't thiiink the error message is related to any of my changes |
It looks like azure pipelines has added an undocumented postgresql install that prevents us installing it 🙄 I'm going to merge your PR anyway and I guess today is now a CI day. |
Thanks for all your hard work on this @azhard! I'm going to merge this and it'll ship in 0.18.0. |
resolves #2520
Description
Implements functionality to rename BigQuery relations using dbt.
Checklist
CHANGELOG.md
and added information about my change to the "dbt next" section.