Skip to content

Commit

Permalink
Minor: Parse GlossaryTerm ChangeDescription gracefully (open-metadata…
Browse files Browse the repository at this point in the history
  • Loading branch information
harshach authored and Shiyang Xiao committed Dec 12, 2023
1 parent 4235580 commit 65db544
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
import org.apache.commons.lang.exception.ExceptionUtils;
import org.apache.commons.lang3.tuple.ImmutablePair;
import org.apache.commons.lang3.tuple.Pair;
import org.openmetadata.common.utils.CommonUtil;
import org.openmetadata.schema.EntityInterface;
import org.openmetadata.schema.EntityTimeSeriesInterface;
import org.openmetadata.schema.analytics.ReportData;
Expand Down Expand Up @@ -72,6 +71,7 @@ public class SearchRepository {

private final List<String> inheritableFields =
List.of(Entity.FIELD_OWNER, Entity.FIELD_DOMAIN, Entity.FIELD_DISABLED);
private final List<String> propagateFields = List.of(Entity.FIELD_TAGS);

@Getter private final ElasticSearchConfiguration elasticSearchConfiguration;

Expand Down Expand Up @@ -299,18 +299,21 @@ public void propagateInheritedFieldsToChildren(
public void propagateGlossaryTags(String entityType, String glossaryFQN, ChangeDescription changeDescription) {
Map<String, Object> fieldData = new HashMap<>();
if (changeDescription != null && entityType.equalsIgnoreCase(Entity.GLOSSARY_TERM)) {

if (!CommonUtil.nullOrEmpty(changeDescription.getFieldsAdded())) {
List<TagLabel> tagLabels =
JsonUtils.readObjects((String) changeDescription.getFieldsAdded().get(0).getNewValue(), TagLabel.class);
tagLabels.forEach(tagLabel -> tagLabel.setLabelType(TagLabel.LabelType.DERIVED));
fieldData.put("tagAdded", tagLabels);
for (FieldChange field : changeDescription.getFieldsAdded()) {
if (propagateFields.contains(field.getName())) {
List<TagLabel> tagLabels =
JsonUtils.readObjects((String) changeDescription.getFieldsAdded().get(0).getNewValue(), TagLabel.class);
tagLabels.forEach(tagLabel -> tagLabel.setLabelType(TagLabel.LabelType.DERIVED));
fieldData.put("tagAdded", tagLabels);
}
}
if (!CommonUtil.nullOrEmpty(changeDescription.getFieldsDeleted())) {
List<TagLabel> tagLabels =
JsonUtils.readObjects((String) changeDescription.getFieldsDeleted().get(0).getOldValue(), TagLabel.class);
tagLabels.forEach(tagLabel -> tagLabel.setLabelType(TagLabel.LabelType.DERIVED));
fieldData.put("tagDeleted", tagLabels);
for (FieldChange field : changeDescription.getFieldsDeleted()) {
if (propagateFields.contains(field.getName())) {
List<TagLabel> tagLabels =
JsonUtils.readObjects((String) changeDescription.getFieldsDeleted().get(0).getOldValue(), TagLabel.class);
tagLabels.forEach(tagLabel -> tagLabel.setLabelType(TagLabel.LabelType.DERIVED));
fieldData.put("tagDeleted", tagLabels);
}
}
searchClient.updateChildren(
GLOBAL_SEARCH_ALIAS,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ public static Map<String, Float> getFields() {
fields.put("columns.name", 2.0f);
fields.put("columns.name.ngram", 1.0f);
fields.put("columns.displayName", 1.0f);
fields.put("columns.description", 1.0f);
fields.put("columns.children.name", 2.0f);
return fields;
}
Expand Down

0 comments on commit 65db544

Please sign in to comment.