-
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
Add a BigQuery adapter macro to enable usage of CopyJobs #2709
Add a BigQuery adapter macro to enable usage of CopyJobs #2709
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.
Thanks for opening this PR, these changes mostly look good! I see one issue where you accessed something that we should have hidden (sorry) and it doesn't exist anymore. I assume your tests will fail because of it.
I also had a flavor/style-related suggestion around the split between the adapter and the connection manager.
plugins/bigquery/dbt/include/bigquery/macros/materializations/copy.sql
Outdated
Show resolved
Hide resolved
@beckjake made an attempt at some integration tests, but I can't say I've got super high confidence they're right (and I don't think I can kick them off) |
@kconvey They should automatically kick off once you push, no need for us to intervene anymore! It looks flake8 is upset about some newline/indentation related triviality. |
@kconvey I think the tests for your new changes aren't showing up at the bottom because of the CHANGELOG.md conflict. I can fix that up for you via the web interface if you'd like, or you can do it. Either way, it should fix the box at the bottom saying they failed |
I've been looking at the tests at the commit level (rather than the bottom of the comments here), and they've been correctly failing, so I've been iterating on them. Planning to merge CHANGELOG.md at the end. |
@beckjake got the following:
I'm guessing I should maybe separate the models I expect to pass in one run and the model I expect to fail in another, but should I not be getting a results list here? |
I think you'll have to for this test. What's happening is that the |
I'm looking through this PR and I'm less sure about it. It seems to me that:
I think I understand why this is the path you've gone down (you can't easily pass the source into the materialization), but this will be a weird behavior that doesn't work with the rest of dbt. In particular, I think Here's an alternative approach that might be better:
do something like this (untested, but...): {# there should be exactly one ref or exactly one source #}
{% set destination = this.incorporate(type='table') %}
{% set dependency_type = none %}
{% if (model.refs | length) == 1 and (model.sources | length) == 0 %}
{% set dependency_type = 'ref' %}
{% elif (model.refs | length) == 0 and (model.sources | length) == 1 %}
{% set dependency_type = 'source' %}
{% else %}
{% set msg %}
Expected exactly one ref or exactly one source, instead got {{ model.refs | length }} models and {{ model.sources | length }} sources.
{% endset %}
{% do exceptions.raise_compiler_error(msg) %}
{% endif %}
{% if dependency_type == 'ref' %}
{% set src = ref(*model.refs[0]) %}
{% else %}
{% set src = source(*model.sources[0]) %}
{% endif %}
{{ adapter.copy_table(
src,
destination,
config.get('copy_materialization')) }}
{# Clean up #}
{{ run_hooks(post_hooks) }}
{{ adapter.commit() }}
{{ return({'relations': [destination]}) }} Then your models, instead of looking like
Could look like this:
The |
That's a good point, I forgot about |
Looks to be passing, and can hopefully be merged. Thanks for the suggestions & help with this @beckjake ! |
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.
This looks great, thanks!
I'm going to manually resolve these conflicts and merge this, they look minor. |
I'm assuming one is probably the CHANGELOG.md after #2711 |
Yup, that and an import in the unit tests. As soon as the bq tests pass, I'm merging this so we can get rc1 out! |
resolves #2696
Description
Adds a macro
copy_table
to use BigQuery's CopyJob, which accepts a relation like{{ copy_table(ref('merged_table')) }}
and can be invoked when the materialization istable
orincremental
(to truncate or append to the destination table).Checklist
CHANGELOG.md
and added information about my change to the "dbt next" section.