Skip to content

Commit

Permalink
[Issue-16906] Fix Lineage Edge Being Removed in Non-Indexable Fields (#…
Browse files Browse the repository at this point in the history
…16907)

* Fix Lineage Edge Being Removed

* Else Condition

(cherry picked from commit 02e06c7)
  • Loading branch information
mohityadav766 committed Jul 3, 2024
1 parent cd966c9 commit 14fea30
Showing 1 changed file with 15 additions and 13 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package org.openmetadata.service.search;

import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
import org.openmetadata.schema.type.EntityReference;
import org.openmetadata.schema.type.TagLabel;

Expand Down Expand Up @@ -32,20 +34,20 @@ public static void removeFieldByPath(Map<String, Object> jsonMap, String path) {
String[] pathElements = path.split("\\.");
Map<String, Object> currentMap = jsonMap;

for (int i = 0; i < pathElements.length - 1; i++) {
String key = pathElements[i];
Object value = currentMap.get(key);
if (value instanceof Map) {
currentMap = (Map<String, Object>) value;
} else if (value instanceof List) {
List<Map<String, Object>> list = (List<Map<String, Object>>) value;
for (Map<String, Object> item : list) {
removeFieldByPath(item, pathElements[i + 1]);
}
} else {
// Path Not Found
return;
String key = pathElements[0];
Object value = currentMap.get(key);
if (value instanceof Map) {
currentMap = (Map<String, Object>) value;
} else if (value instanceof List) {
List<Map<String, Object>> list = (List<Map<String, Object>>) value;
for (Map<String, Object> item : list) {
removeFieldByPath(
item,
Arrays.stream(pathElements, 1, pathElements.length).collect(Collectors.joining(".")));
}
return;
} else {
return;
}

// Remove the field at the last path element
Expand Down

0 comments on commit 14fea30

Please sign in to comment.