dbt-databricks icon indicating copy to clipboard operation
dbt-databricks copied to clipboard

MERGE with explicit actions, support for multi-actions

Open mi-volodin opened this issue 1 year ago • 17 comments

Resolves #949

Description

This PR extends the capability of Merge strategy configuration and allow to completely override actions block with an explicit statement.

E.g. it allows to define multiple actions with multiple conditions and tune this part at developer's convenience.

when matched and ... then update
...
when matched and ... then delete
when not matched and ... then insert
...

Checklist

  • [x] I have run this code in development and it appears to resolve the stated issue
  • [x] This PR includes tests, or tests are not required/relevant for this PR
  • [ ] I have updated the CHANGELOG.md and added information about my change to the "dbt-databricks next" section.

mi-volodin avatar May 12 '25 18:05 mi-volodin

There are some extra actions on docs + changelog, but the code is ready for review.

@benc-db could you please trigger the tests on your side? My functional tests with snapshots traditionally doesn't work.

mi-volodin avatar May 12 '25 18:05 mi-volodin

Yep, of course, I'll write a docs entry meanwhile.

mi-volodin avatar May 13 '25 07:05 mi-volodin

For transparency - it was decided to pause this PR activities until the principal decision would be made to introduce that functionality in that form.

mi-volodin avatar May 14 '25 09:05 mi-volodin

@mi-volodin @benc-db are there any further updates on this?

We have a similar need for multiple matches and I'd rather use something native rather than creating a modified version.

With the native databricks merge functionality progressing very fast, it makes sense to have custom sql expressions for the merge rather than loads of potential keys and extra config options which become increasingly more complex to maintain.

asos-dipeshbhundia avatar Dec 30 '25 16:12 asos-dipeshbhundia

@asos-dipeshbhundia there were no further proceedings, IIRC mostly due to the coincidental release of dbt fusion at that time.

I personally also still would like to have this functionality, but only if the concept would be approved to go on with by @benc-db . The branch is apparently outdated and I'll be happy to rebase it if needed.

mi-volodin avatar Jan 02 '26 10:01 mi-volodin

@mi-volodin Thanks, internally we have created our own incremental strategy to allow custom merge actions. We have an extra property under meta called custom merge actions which allows sql.

image

The merge is pretty much just a cut down version of get_incremental_merge_sql image

asos-dipeshbhundia avatar Jan 08 '26 11:01 asos-dipeshbhundia

Did you create your own merge macro to use it?

mi-volodin avatar Jan 08 '26 13:01 mi-volodin

@sd-db the person in dbt Labs product that pushed back on this is no longer there. We should consider bringing this up again.

benc-db avatar Jan 08 '26 20:01 benc-db

yes, i created my own version of the existing merge pattern cutting down the existing options to keep it simple complex_merge.sql

asos-dipeshbhundia avatar Jan 09 '26 13:01 asos-dipeshbhundia

@benc-db great 😄
Then I will rebase the changes on main or, if 1.11.4 will be released, on 1.11 latest, right?

mi-volodin avatar Jan 09 '26 15:01 mi-volodin

@mi-volodin I'd hold off on rebasing, as they might still tell us not to merge it. I'm just suggesting its worth it for us to bring up in our product meetings with them to see if their position has softened. Thanks however for your eagerness to improve the adapter for others :)

benc-db avatar Jan 09 '26 16:01 benc-db

@benc-db ah 🥲 sorry, I've read it wrongly. Then keeping it on ice until there will be some news.

At least now there's a proof that it's not only needed, but actually achieved (in a potentially non-uniform way if implemented by others from scratch) with the ad-hoc strategy overloading. For me it looks like quite a good argument to proceed.

mi-volodin avatar Jan 09 '26 17:01 mi-volodin

Hello @benc-db @mi-volodin, I think this merge feature is very important. It is a core functionality of DBT Databricks for data engineering and BI use cases. Will there be any progress on this, please?

liangonli avatar May 05 '26 08:05 liangonli

@benc-db just for the case I rebased to the tip of the main 😉

mi-volodin avatar May 07 '26 17:05 mi-volodin

@sd-db @tejassp-db

Hi! Got the message from Ben that you are now the core maintainers. Therefore tagging you with a kind request to look into the topic.

I can share the context if needed.

mi-volodin avatar May 08 '26 12:05 mi-volodin

@sd-db @jprakash-db sorry, just a kind reminder to look into this PR. At least some feedback on the plans is really-really appreciated.

mi-volodin avatar May 27 '26 13:05 mi-volodin

Sorry on the long wait, had been busy with a few other things. Let me a take a look next week. On the top of my list 👍

sd-db avatar Jun 19 '26 13:06 sd-db

@sd-db Any news? At least to understand if we are still up to consider this concept.

mi-volodin avatar Jul 08 '26 17:07 mi-volodin

@sd-db Any news on this ?

rodrigorabioglio avatar Jul 10 '26 18:07 rodrigorabioglio

@mi-volodin Thanks, finally got to this PR. Overall direction seems good. Should be open to this in 1.13. I think the current PR can do a bit more on testing, the other think I am concerned on is dbt-core warnings; which is raised on every config that is not documented in the json_schema (need to check a bit more); but think should be fine for this use-case as this is a sufficiently advanced use-case and I assume folks who need this should be able to work through the warnings etc.

sd-db avatar Jul 19 '26 08:07 sd-db