Skip to content

feat(incremental): copy multiple tables in parallel (#1237) #1413

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

AxelThevenot
Copy link

resolves dbt-labs/dbt-adapters#559
N/A dbt-labs/docs.getdbt.com/#

Problem

Copy partitions and tables in parallel instead of sequentially which is slow for large partition management

Solution

Run jobs in parallel and waits for the results.

Checklist

  • I have read the contributing guide and understand what's expected of me
  • I have run this code in development and it appears to resolve the stated issue
  • This PR includes tests, or tests are not required/relevant for this PR
  • This PR has no interface changes (e.g. macros, cli, logs, json artifacts, config files, adapter interface, etc) or this PR has already received feedback and approval from Product or DX

@AxelThevenot AxelThevenot requested a review from a team as a code owner November 25, 2024 23:06
Copy link

@leohoare leohoare left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a maintainer but this is a much needed feature, thanks @AxelThevenot 🙌🏻
Large datasets with a lot of partitions currently performs quite poorly.

I looked into doing this directly with one call copy_table call but it doesn't look like it's possible currently (unless we delete the partitions upfront and use write_append)

@leohoare
Copy link

@mikealfare @colin-rogers-dbt could we get your thoughts / a review of this one?
(or tag the appropriate maintainer/s?)

@andreypanchenko
Copy link

Is there any progress here?

@Pirognoe
Copy link

Pirognoe commented May 6, 2025

This would help a lot

Copy link

cla-bot bot commented May 6, 2025

Thank you for your pull request and welcome to our community. We could not parse the GitHub identity of the following contributors: axel_thevenot.
This is most likely caused by a git client misconfiguration; please make sure to:

  1. check if your git client is configured with an email to sign commits git config --list | grep email
  2. If not, set it up using git config --global user.email [email protected]
  3. Make sure that the git commit email is configured in your GitHub account settings, see https://github.com/settings/emails

@AxelThevenot AxelThevenot force-pushed the feat/1237/copy-tables-and-partition-in-parallel branch from ece2ad3 to b5336ae Compare May 6, 2025 14:30
@cla-bot cla-bot bot added the cla:yes label May 6, 2025
@ursuser
Copy link

ursuser commented May 8, 2025

looks very helpful for large incremental models, would love to see this merged

@andreypanchenko
Copy link

@leohoare
Hello, we have a lot of likes here, could you please help with the promotion of it?

@leohoare
Copy link

@andreypanchenko I'm not a maintainer, I'll post it in dbt-bigquery slack to rally some attention.

@VersusFacit
Copy link
Contributor

Hey folks, I've got eyes on this and taking some extra time to get this merged on the side (we're all hands on deck for other things ahead of 5/28 this month, but I know how important this change is, so I'm taking extra work hours to shepherd it along -- with that context in mind, please bear with me 🙇‍♀️ )

I need to trace over the code and get a solid idea of what's happening at each step since this has a pretty big surface area and add tests for any behaviors this alters or introduces that aren't already tested. I'll parse over this / do research on the changes tomorrow with a colleague so we can fast track the change as much as possible (two minds better than one for this sort of thing).

Also, we're going to need to do this merge over in dbt-adapters.

@AxelThevenot either I'll do that later this week or you can get the jump on me by doing it sooner. Either way.

@@ -18,23 +18,27 @@

{% macro bq_copy_partitions(tmp_relation, target_relation, partitions, partition_by) %}
Copy link
Contributor

@VersusFacit VersusFacit May 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

internal dbt convo: plan to leave the the macro itself for the user interface (no breaking changes) but we figured this control flow can (and should) be pushed down into Python

{% endif %}
{% set tmp_relation_partitioned = api.Relation.create(database=tmp_relation.database, schema=tmp_relation.schema, identifier=tmp_relation.table ~ '$' ~ partition, type=tmp_relation.type) %}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note to self: partition fqns now handled in Python (see copy_bq_table)

@@ -409,7 +409,7 @@ def _agate_to_schema(
return bq_schema

@available.parse(lambda *a, **k: "")
def copy_table(self, source, destination, materialization):
def copy_table(self, source, destination, materialization, partition_ids=None):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dbt internal convo: double check no issues with base adapter (don't think so but we have to check)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@VersusFacit
Is there any news on it?

@dongchris
Copy link

any update on this? @AxelThevenot

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Feature] support copy multiple tables in parallel using copy_partitions
8 participants