From c221f80d1545df93fc9ce89cef414d2d5473712f Mon Sep 17 00:00:00 2001 From: IceS2 Date: Tue, 13 Aug 2024 18:28:33 +0200 Subject: [PATCH] Fix DataInsights Field Getter (#17427) --- .../elasticsearch/ElasticSearchClient.java | 17 +++++++++-------- .../search/opensearch/OpenSearchClient.java | 17 +++++++++-------- 2 files changed, 18 insertions(+), 16 deletions(-) diff --git a/openmetadata-service/src/main/java/org/openmetadata/service/search/elasticsearch/ElasticSearchClient.java b/openmetadata-service/src/main/java/org/openmetadata/service/search/elasticsearch/ElasticSearchClient.java index a9c1bb03ef4..11ad120561a 100644 --- a/openmetadata-service/src/main/java/org/openmetadata/service/search/elasticsearch/ElasticSearchClient.java +++ b/openmetadata-service/src/main/java/org/openmetadata/service/search/elasticsearch/ElasticSearchClient.java @@ -2010,6 +2010,7 @@ public class ElasticSearchClient implements SearchClient { @Override public List> fetchDIChartFields() throws IOException { + List> fields = new ArrayList<>(); GetMappingsRequest request = new GetMappingsRequest().indices(DataInsightSystemChartRepository.DI_SEARCH_INDEX); @@ -2020,11 +2021,9 @@ public class ElasticSearchClient implements SearchClient { for (Map.Entry entry : response.mappings().entrySet()) { // Get fields for the index Map indexFields = entry.getValue().sourceAsMap(); - List> fields = new ArrayList<>(); getFieldNames((Map) indexFields.get("properties"), "", fields); - return fields; } - return null; + return fields; } void getFieldNames( @@ -2045,11 +2044,13 @@ public class ElasticSearchClient implements SearchClient { getFieldNames( (Map) subFields.get("properties"), fieldName + ".", fieldList); } else { - Map map = new HashMap<>(); - map.put("name", fieldName); - map.put("displayName", fieldNameOriginal); - map.put("type", type); - fieldList.add(map); + if (fieldList.stream().noneMatch(e -> e.get("name").equals(fieldName))) { + Map map = new HashMap<>(); + map.put("name", fieldName); + map.put("displayName", fieldNameOriginal); + map.put("type", type); + fieldList.add(map); + } } } } diff --git a/openmetadata-service/src/main/java/org/openmetadata/service/search/opensearch/OpenSearchClient.java b/openmetadata-service/src/main/java/org/openmetadata/service/search/opensearch/OpenSearchClient.java index 8e3ee055850..cd13a2ec519 100644 --- a/openmetadata-service/src/main/java/org/openmetadata/service/search/opensearch/OpenSearchClient.java +++ b/openmetadata-service/src/main/java/org/openmetadata/service/search/opensearch/OpenSearchClient.java @@ -1987,6 +1987,7 @@ public class OpenSearchClient implements SearchClient { @Override public List> fetchDIChartFields() throws IOException { + List> fields = new ArrayList<>(); GetMappingsRequest request = new GetMappingsRequest().indices(DataInsightSystemChartRepository.DI_SEARCH_INDEX); @@ -1997,11 +1998,9 @@ public class OpenSearchClient implements SearchClient { for (Map.Entry entry : response.mappings().entrySet()) { // Get fields for the index Map indexFields = entry.getValue().sourceAsMap(); - List> fields = new ArrayList<>(); getFieldNames((Map) indexFields.get("properties"), "", fields); - return fields; } - return null; + return fields; } void getFieldNames( @@ -2022,11 +2021,13 @@ public class OpenSearchClient implements SearchClient { getFieldNames( (Map) subFields.get("properties"), fieldName + ".", fieldList); } else { - Map map = new HashMap<>(); - map.put("name", fieldName); - map.put("displayName", fieldNameOriginal); - map.put("type", type); - fieldList.add(map); + if (fieldList.stream().noneMatch(e -> e.get("name").equals(fieldName))) { + Map map = new HashMap<>(); + map.put("name", fieldName); + map.put("displayName", fieldNameOriginal); + map.put("type", type); + fieldList.add(map); + } } } }