fix(engine_adapter): put the merge insert before NOT MATCHED BY SOURCE - #6111
Open
manan28025 wants to merge 1 commit into
Open
manan28025 wants to merge 1 commit into
manan28025 wants to merge 1 commit into
Conversation
merge() always appended its WHEN NOT MATCHED THEN INSERT clause after the when_matched clauses. If those include WHEN NOT MATCHED BY SOURCE, the insert ended up after it, which Databricks rejects because it requires WHEN MATCHED, WHEN NOT MATCHED [BY TARGET], WHEN NOT MATCHED BY SOURCE in that order. The insert now goes before the first BY SOURCE clause. Signed-off-by: neatninja <manan81140@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Fixes #5355.
EngineAdapter.merge()always appends itsWHEN NOT MATCHED THEN INSERTclause after thewhen_matchedclauses. If those includeWHEN NOT MATCHED BY SOURCE, the insert ends up after it. Databricks requires the orderWHEN MATCHED,WHEN NOT MATCHED [BY TARGET],WHEN NOT MATCHED BY SOURCE, so the generated MERGE fails with a syntax error.The insert now goes in front of the first
WHEN NOT MATCHED BY SOURCEclause. Without such a clause it is still appended last, so other generated SQL doesn't change.Test Plan
test_merge_when_not_matched_by_source. It fails on main (the insert comes after the BY SOURCE clause) and passes with the fix.Checklist
make styleand fixed any issues (ruff and ruff-format pass)make fast-test) (ran the engine adapter and snapshot evaluator suites)git commit -s) per the DCO