diff --git a/openmetadata-service/src/main/java/org/openmetadata/service/apps/bundles/insights/workflows/dataAssets/processors/DataInsightsEntityEnricherProcessor.java b/openmetadata-service/src/main/java/org/openmetadata/service/apps/bundles/insights/workflows/dataAssets/processors/DataInsightsEntityEnricherProcessor.java index 8782ce2c51d..3b229bb4ca1 100644 --- a/openmetadata-service/src/main/java/org/openmetadata/service/apps/bundles/insights/workflows/dataAssets/processors/DataInsightsEntityEnricherProcessor.java +++ b/openmetadata-service/src/main/java/org/openmetadata/service/apps/bundles/insights/workflows/dataAssets/processors/DataInsightsEntityEnricherProcessor.java @@ -13,6 +13,7 @@ import java.util.List; import java.util.Map; import java.util.Optional; import java.util.Set; +import lombok.Getter; import lombok.extern.slf4j.Slf4j; import org.glassfish.jersey.internal.util.ExceptionUtils; import org.openmetadata.common.utils.CommonUtil; @@ -173,7 +174,9 @@ public class DataInsightsEntityEnricherProcessor entityMap.put("descriptionSources", processDescriptionSources(entity, changeSummaryMap)); // Process Tag Source - entityMap.put("tagSources", processTagSources(entity)); + TagAndTierSources tagAndTierSources = processTagAndTierSources(entity); + entityMap.put("tagSources", tagAndTierSources.getTagSources()); + entityMap.put("tierSources", tagAndTierSources.getTierSources()); // Process Team Optional.ofNullable(processTeam(entity)).ifPresent(team -> entityMap.put("team", team)); @@ -299,37 +302,50 @@ public class DataInsightsEntityEnricherProcessor return team; } - private void processTagSources(List tagList, Map tagSources) { + private void processTagAndTierSources( + List tagList, TagAndTierSources tagAndTierSources) { Optional.ofNullable(tagList) .ifPresent( tags -> { - tags.stream() - .filter(tag -> !tag.getTagFQN().startsWith("Tier.")) - .map(tag -> tag.getLabelType().value()) - .forEach( - tagSource -> - tagSources.put(tagSource, tagSources.getOrDefault(tagSource, 0) + 1)); + tags.forEach( + tag -> { + String tagSource = tag.getLabelType().value(); + if (tag.getTagFQN().startsWith("Tier.")) { + tagAndTierSources + .getTierSources() + .put( + tagSource, + tagAndTierSources.getTierSources().getOrDefault(tagSource, 0) + 1); + } else { + tagAndTierSources + .getTagSources() + .put( + tagSource, + tagAndTierSources.getTagSources().getOrDefault(tagSource, 0) + 1); + } + }); }); } - private void processEntityTagSources(EntityInterface entity, Map tagSources) { - processTagSources(entity.getTags(), tagSources); + private void processEntityTagSources( + EntityInterface entity, TagAndTierSources tagAndTierSources) { + processTagAndTierSources(entity.getTags(), tagAndTierSources); } private void processColumnTagSources( - ColumnsEntityInterface entity, Map tagSources) { + ColumnsEntityInterface entity, TagAndTierSources tagAndTierSources) { for (Column column : entity.getColumns()) { - processTagSources(column.getTags(), tagSources); + processTagAndTierSources(column.getTags(), tagAndTierSources); } } - private Map processTagSources(EntityInterface entity) { - Map tagSources = new HashMap<>(); - processEntityTagSources(entity, tagSources); + private TagAndTierSources processTagAndTierSources(EntityInterface entity) { + TagAndTierSources tagAndTierSources = new TagAndTierSources(); + processEntityTagSources(entity, tagAndTierSources); if (hasColumns(entity)) { - processColumnTagSources((ColumnsEntityInterface) entity, tagSources); + processColumnTagSources((ColumnsEntityInterface) entity, tagAndTierSources); } - return tagSources; + return tagAndTierSources; } private String processTier(EntityInterface entity) { @@ -395,4 +411,15 @@ public class DataInsightsEntityEnricherProcessor public StepStats getStats() { return stats; } + + @Getter + public static class TagAndTierSources { + private final Map tagSources; + private final Map tierSources; + + public TagAndTierSources() { + this.tagSources = new HashMap<>(); + this.tierSources = new HashMap<>(); + } + } }