databricks / dbt-databricks

A dbt adapter for Databricks.
https://databricks.com
Apache License 2.0
209 stars 110 forks source link

Support for custom incremental strategies #753

Open mcowart123 opened 1 month ago

mcowart123 commented 1 month ago

Describe the feature

Adding support for Custom Incremental Strategies.

Who will this benefit?

This will allow users to easily modify the MERGE command to take into account additional data from the table_changes function (for example)

merge into {{ target }} as DBT_INTERNAL_DEST
      using {{ source }} as DBT_INTERNAL_SOURCE
      on {{ predicates | join(' and ') }}
      when matched and DBT_INTERNAL_SOURCE._change_type = 'update_postimage' then update set {{ get_merge_update_set(update_columns, on_schema_change, source_columns) }}
      when not matched and DBT_INTERNAL_SOURCE._change_type != 'delete' then insert {{ get_merge_insert(on_schema_change, source_columns) }}
      when matched and DBT_INTERNAL_SOURCE._change_type = 'delete' then delete
benc-db commented 1 month ago

Do you have some idea what is preventing custom incremental strategies?

mcowart123 commented 1 month ago

When I tried adding one dbt run failed with the following (I named the custom strategy merge_table_changes):

Invalid incremental strategy provided: merge_table_changes
      Expected one of: 'merge', 'replace_where', 'append', 'insert_overwrite'

Looking at a similar issue reported here it seems this is the response when custom strategies aren't supported; dbt-databricks itself is called out in that response.

Another issue here is similar and that is talking about if there's not an adapter macro to get your custom strategy macro it will fail.

benc-db commented 1 month ago

Thanks for detail; I don't see any particular reason to block this, so when I get some time I'll look into what it would take to support it.