-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Fixes #26737: Remove stale dbt automated tags #27368
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
mohitjeswani01
wants to merge
7
commits into
open-metadata:main
Choose a base branch
from
mohitjeswani01:fix/26737-dbt-automated-tag-removal
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+196
−0
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
6e5eaa8
Fix dbt automated tag removal in addDataModel
mohitjeswani01 df8b1c4
Address review feedback for dbt automated tag cleanup
mohitjeswani01 f3c5f1f
chore: apply spotless formatting to fix checkstyle
mohitjeswani01 a59e8c6
test: update Mockito stub to accept null incoming tags list
mohitjeswani01 ceb67d2
ran mvn spotless:apply
mohitjeswani01 23324a2
Merge branch 'main' into fix/26737-dbt-automated-tag-removal
mohitjeswani01 92299e3
Merge branch 'main' into fix/26737-dbt-automated-tag-removal
mohitjeswani01 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
165 changes: 165 additions & 0 deletions
165
...service/src/test/java/org/openmetadata/service/jdbi3/TableRepositoryDataModelTagTest.java
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,165 @@ | ||
| package org.openmetadata.service.jdbi3; | ||
|
|
||
| import static org.junit.jupiter.api.Assertions.assertEquals; | ||
| import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
|
||
| import java.util.List; | ||
| import org.junit.jupiter.api.Test; | ||
| import org.mockito.Mockito; | ||
| import org.openmetadata.schema.type.DataModel; | ||
| import org.openmetadata.schema.type.TagLabel; | ||
| import org.openmetadata.service.Entity; | ||
| import org.openmetadata.service.resources.tags.TagLabelUtil; | ||
|
|
||
| /** | ||
| * Tests for dbt AUTOMATED tag cleanup behavior introduced in TableRepository.addDataModel. | ||
| * | ||
| * <p>These tests mirror the tag-merging logic used in addDataModel, focusing on how | ||
| * AUTOMATED tags applied by the ingestion-bot are removed when no longer present in the | ||
| * incoming dbt data model, while preserving other tags. | ||
| */ | ||
| class TableRepositoryDataModelTagTest { | ||
|
|
||
| private static final TableRepository tableRepository; | ||
|
|
||
| static { | ||
| tableRepository = Mockito.mock(TableRepository.class); | ||
| Mockito.when( | ||
| tableRepository.removeStaleDbtAutomatedTags( | ||
| Mockito.anyList(), Mockito.nullable(List.class))) | ||
| .thenCallRealMethod(); | ||
| } | ||
|
|
||
| private List<TagLabel> applyDbtTableTagUpdate( | ||
| List<TagLabel> existingTableTags, DataModel dataModel) { | ||
| List<TagLabel> mergedTableTags = | ||
| TagLabelUtil.mergeTagsWithIncomingPrecedence(existingTableTags, dataModel.getTags()); | ||
| if (DataModel.ModelType.DBT.equals(dataModel.getModelType())) { | ||
| mergedTableTags = | ||
| tableRepository.removeStaleDbtAutomatedTags(mergedTableTags, dataModel.getTags()); | ||
| } | ||
| return mergedTableTags; | ||
| } | ||
|
|
||
| private List<TagLabel> applyDbtColumnTagUpdate( | ||
| List<TagLabel> storedColumnTags, DataModel dataModel, List<TagLabel> modelColumnTags) { | ||
| List<TagLabel> mergedColumnTags = | ||
| TagLabelUtil.mergeTagsWithIncomingPrecedence(storedColumnTags, modelColumnTags); | ||
| if (DataModel.ModelType.DBT.equals(dataModel.getModelType())) { | ||
| mergedColumnTags = | ||
| tableRepository.removeStaleDbtAutomatedTags(mergedColumnTags, modelColumnTags); | ||
| } | ||
| return mergedColumnTags; | ||
| } | ||
|
|
||
| private TagLabel automatedDbtTag(String fqn) { | ||
| return new TagLabel() | ||
| .withTagFQN(fqn) | ||
| .withSource(TagLabel.TagSource.CLASSIFICATION) | ||
| .withLabelType(TagLabel.LabelType.AUTOMATED) | ||
| .withAppliedBy(Entity.INGESTION_BOT_NAME); | ||
| } | ||
|
|
||
| private TagLabel automatedOtherBotTag(String fqn) { | ||
| return new TagLabel() | ||
| .withTagFQN(fqn) | ||
| .withSource(TagLabel.TagSource.CLASSIFICATION) | ||
| .withLabelType(TagLabel.LabelType.AUTOMATED) | ||
| .withAppliedBy("other-bot"); | ||
| } | ||
|
|
||
| private TagLabel manualTag(String fqn) { | ||
| return new TagLabel() | ||
| .withTagFQN(fqn) | ||
| .withSource(TagLabel.TagSource.CLASSIFICATION) | ||
| .withLabelType(TagLabel.LabelType.MANUAL) | ||
| .withAppliedBy("some-user"); | ||
| } | ||
|
|
||
| private boolean containsTagFqn(List<TagLabel> tags, String fqn) { | ||
| return tags.stream().anyMatch(t -> fqn.equals(t.getTagFQN())); | ||
| } | ||
|
|
||
| @Test | ||
| void dbtTableTags_staleAutomatedTagsFromIngestionBotAreRemoved() { | ||
| TagLabel staleAutomated = automatedDbtTag("Classification.Stale"); | ||
| TagLabel keptAutomated = automatedDbtTag("Classification.Kept"); | ||
| TagLabel manual = manualTag("Classification.Manual"); | ||
| TagLabel otherBotAutomated = automatedOtherBotTag("Classification.OtherBot"); | ||
|
|
||
| List<TagLabel> existing = List.of(staleAutomated, keptAutomated, manual, otherBotAutomated); | ||
|
|
||
| DataModel dataModel = new DataModel().withModelType(DataModel.ModelType.DBT); | ||
| dataModel.setTags(List.of(keptAutomated, manual, otherBotAutomated)); | ||
|
|
||
| List<TagLabel> result = applyDbtTableTagUpdate(existing, dataModel); | ||
|
|
||
| assertEquals(3, result.size()); | ||
| assertTrue(containsTagFqn(result, "Classification.Kept")); | ||
| assertTrue(containsTagFqn(result, "Classification.Manual")); | ||
| assertTrue(containsTagFqn(result, "Classification.OtherBot")); | ||
| assertTrue(!containsTagFqn(result, "Classification.Stale")); | ||
| } | ||
|
|
||
| @Test | ||
| void ddlTableTags_automatedTagsAreNotRemoved() { | ||
| TagLabel staleAutomated = automatedDbtTag("Classification.Stale"); | ||
| TagLabel keptAutomated = automatedDbtTag("Classification.Kept"); | ||
| TagLabel manual = manualTag("Classification.Manual"); | ||
| TagLabel otherBotAutomated = automatedOtherBotTag("Classification.OtherBot"); | ||
|
|
||
| List<TagLabel> existing = List.of(staleAutomated, keptAutomated, manual, otherBotAutomated); | ||
|
|
||
| DataModel dataModel = new DataModel().withModelType(DataModel.ModelType.DDL); | ||
| dataModel.setTags(List.of(keptAutomated, manual, otherBotAutomated)); | ||
|
|
||
| List<TagLabel> result = applyDbtTableTagUpdate(existing, dataModel); | ||
|
|
||
| assertEquals(4, result.size()); | ||
| assertTrue(containsTagFqn(result, "Classification.Stale")); | ||
| assertTrue(containsTagFqn(result, "Classification.Kept")); | ||
| assertTrue(containsTagFqn(result, "Classification.Manual")); | ||
| assertTrue(containsTagFqn(result, "Classification.OtherBot")); | ||
| } | ||
|
|
||
| @Test | ||
| void dbtColumnTags_staleAutomatedTagsFromIngestionBotAreRemoved() { | ||
| TagLabel staleAutomated = automatedDbtTag("Classification.Stale"); | ||
| TagLabel keptAutomated = automatedDbtTag("Classification.Kept"); | ||
| TagLabel manual = manualTag("Classification.Manual"); | ||
|
|
||
| List<TagLabel> storedColumnTags = List.of(staleAutomated, keptAutomated, manual); | ||
| List<TagLabel> modelColumnTags = List.of(keptAutomated, manual); | ||
|
|
||
| DataModel dataModel = new DataModel().withModelType(DataModel.ModelType.DBT); | ||
|
|
||
| List<TagLabel> result = applyDbtColumnTagUpdate(storedColumnTags, dataModel, modelColumnTags); | ||
|
|
||
| assertEquals(2, result.size()); | ||
| assertTrue(containsTagFqn(result, "Classification.Kept")); | ||
| assertTrue(containsTagFqn(result, "Classification.Manual")); | ||
| assertTrue(!containsTagFqn(result, "Classification.Stale")); | ||
| } | ||
|
|
||
| @Test | ||
| void removeStaleDbtAutomatedTags_removesAllDbtAutomatedWhenIncomingNullOrEmpty() { | ||
| TagLabel staleAutomated1 = automatedDbtTag("Classification.Stale1"); | ||
| TagLabel staleAutomated2 = automatedDbtTag("Classification.Stale2"); | ||
| TagLabel manual = manualTag("Classification.Manual"); | ||
|
|
||
| List<TagLabel> existing = List.of(staleAutomated1, staleAutomated2, manual); | ||
|
|
||
| DataModel dataModel = new DataModel().withModelType(DataModel.ModelType.DBT); | ||
|
|
||
| List<TagLabel> resultNull = | ||
| tableRepository.removeStaleDbtAutomatedTags(existing, dataModel.getTags()); | ||
| assertEquals(1, resultNull.size()); | ||
| assertTrue(containsTagFqn(resultNull, "Classification.Manual")); | ||
|
|
||
| dataModel.setTags(List.of()); | ||
| List<TagLabel> resultEmpty = | ||
| tableRepository.removeStaleDbtAutomatedTags(existing, dataModel.getTags()); | ||
| assertEquals(1, resultEmpty.size()); | ||
| assertTrue(containsTagFqn(resultEmpty, "Classification.Manual")); | ||
| } | ||
| } | ||
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.