dbt-labs / dbt-adapters

Apache License 2.0
28 stars 38 forks source link

[CT-3120] Migrate `clone` to use `get_replace_sql` macro #225

Open aranke opened 1 year ago

aranke commented 1 year ago

Housekeeping

Short Description

There's a new macro, get_replace_sql, that can be used to replace an existing view with another view atomically.

Acceptance Criteria

Rewrite clone to use this macro. If existing_relation and target_relation are both views, this will dispatch to a create or replace macro using target_relation and sql.

Impact to Other Teams

N/A, but please get Adapters review

Will backports be required?

No

Context

Previous PR: https://github.com/dbt-labs/dbt-core/pull/8355

martynydbt commented 1 year ago

@aranke can you please use the template with the ticket description? thank you! :D

jtcohen6 commented 5 months ago

Moving to dbt-adapters, as that's where the associated implementation logic has also moved.

The likely code to replace:

https://github.com/dbt-labs/dbt-adapters/blob/a2292c8ec76e4c9f03869ad95817a2ad82dfb34b/dbt/include/global_project/macros/materializations/models/clone/clone.sql#L50-L65

We should then move the "after build" steps to take place regardless of whether we've materialized a table clone or a view:

https://github.com/dbt-labs/dbt-adapters/blob/a2292c8ec76e4c9f03869ad95817a2ad82dfb34b/dbt/include/global_project/macros/materializations/models/clone/clone.sql#L44-L48