Skip to content

Commit

Permalink
[#4817] fix(core): Fix unexpected tag delete issue (#5235)
Browse files Browse the repository at this point in the history
### What changes were proposed in this pull request?

This PR fixes the tag relation unexpected deletion issue. Previously we
deleted other unrelated tag relations under the metalake, which will
make the associated tag list fail. So this PR will fix this issue.

### Why are the changes needed?

To fix the tag unexpectedly deleted issue.

Fix: #4817 

### Does this PR introduce _any_ user-facing change?

No.

### How was this patch tested?

Add new IT to fix this issue.
  • Loading branch information
jerryshao authored Oct 25, 2024
1 parent 5b2f823 commit 9ecc87d
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -606,4 +606,43 @@ public void testAssociateTagsToColumn() {
Assertions.assertEquals(1, tag4.associatedObjects().count());
Assertions.assertEquals(column.name(), tag4.associatedObjects().objects()[0].name());
}

@Test
public void testAssociateAndDeleteTags() {
Tag tag1 =
metalake.createTag(
GravitinoITUtils.genRandomName("tag_it_tag1"), "comment1", Collections.emptyMap());
Tag tag2 =
metalake.createTag(
GravitinoITUtils.genRandomName("tag_it_tag2"), "comment2", Collections.emptyMap());
Tag tag3 =
metalake.createTag(
GravitinoITUtils.genRandomName("tag_it_tag3"), "comment3", Collections.emptyMap());

String[] associatedTags =
relationalCatalog
.supportsTags()
.associateTags(new String[] {tag1.name(), tag2.name()}, new String[] {tag3.name()});

Assertions.assertEquals(2, associatedTags.length);
Set<String> tagNames = Sets.newHashSet(associatedTags);
Assertions.assertTrue(tagNames.contains(tag1.name()));
Assertions.assertTrue(tagNames.contains(tag2.name()));
Assertions.assertFalse(tagNames.contains(tag3.name()));

Tag retrivedTag = relationalCatalog.supportsTags().getTag(tag2.name());
Assertions.assertEquals(tag2.name(), retrivedTag.name());
Assertions.assertEquals(tag2.comment(), retrivedTag.comment());

boolean deleted = metalake.deleteTag("null");
Assertions.assertFalse(deleted);

deleted = metalake.deleteTag(tag1.name());
Assertions.assertTrue(deleted);
deleted = metalake.deleteTag(tag1.name());
Assertions.assertFalse(deleted);

String[] associatedTags1 = relationalCatalog.supportsTags().listTags();
Assertions.assertArrayEquals(new String[] {tag2.name()}, associatedTags1);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ public String softDeleteTagMetadataObjectRelsByMetalakeAndTagName(
+ " tm WHERE tm.metalake_id IN (SELECT mm.metalake_id FROM "
+ MetalakeMetaMapper.TABLE_NAME
+ " mm WHERE mm.metalake_name = #{metalakeName} AND mm.deleted_at = 0)"
+ " AND tm.deleted_at = 0) AND te.deleted_at = 0";
+ " AND tm.tag_name = #{tagName} AND tm.deleted_at = 0) AND te.deleted_at = 0";
}

public String softDeleteTagMetadataObjectRelsByMetalakeId(@Param("metalakeId") Long metalakeId) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public String softDeleteTagMetadataObjectRelsByMetalakeAndTagName(
+ " tm WHERE tm.metalake_id IN (SELECT mm.metalake_id FROM "
+ MetalakeMetaMapper.TABLE_NAME
+ " mm WHERE mm.metalake_name = #{metalakeName} AND mm.deleted_at = 0)"
+ " AND tm.deleted_at = 0) AND te.deleted_at = 0";
+ " AND tm.tag_name = #{tagName} AND tm.deleted_at = 0) AND te.deleted_at = 0";
}

@Override
Expand Down

0 comments on commit 9ecc87d

Please sign in to comment.