From 07692620d3f9f6a031df8f72fd994cce82bd08f5 Mon Sep 17 00:00:00 2001 From: naveenaechan Date: Fri, 10 Nov 2023 16:01:18 +0530 Subject: [PATCH] PLT-191: atlas search: method level --- .../discovery/EntityDiscoveryService.java | 25 ++++++++++--------- 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/repository/src/main/java/org/apache/atlas/discovery/EntityDiscoveryService.java b/repository/src/main/java/org/apache/atlas/discovery/EntityDiscoveryService.java index b47b467bf9..9ef5ac9186 100644 --- a/repository/src/main/java/org/apache/atlas/discovery/EntityDiscoveryService.java +++ b/repository/src/main/java/org/apache/atlas/discovery/EntityDiscoveryService.java @@ -1042,18 +1042,19 @@ private void prepareSearchResult(AtlasSearchResult ret, DirectIndexQueryResult i if(LOG.isDebugEnabled()){ LOG.debug("Preparing search results for ({})", ret.getSearchParameters()); } - - Stream resultStream = StreamSupport.stream(Spliterators.spliteratorUnknownSize(indexQueryResult.getIterator(), Spliterator.ORDERED), true); - Map vertexIds = resultStream.collect(Collectors.toMap(Result::getId, result -> result)); - List resultVertices = graph.getVertices(vertexIds.keySet().toArray()); - List headers = resultVertices.parallelStream().map(v -> { - try { - return enrichVertex(ret, resultAttributes, vertexIds.get(v.getId()), v, fetchCollapsedResults); - } catch (AtlasBaseException e) { - throw new RuntimeException(e); - } - }).collect(Collectors.toList()); - headers.forEach(ret::addEntity); + if (indexQueryResult.getIterator().hasNext()) { + Stream resultStream = StreamSupport.stream(Spliterators.spliteratorUnknownSize(indexQueryResult.getIterator(), Spliterator.ORDERED), true); + Map vertexIds = resultStream.collect(Collectors.toMap(Result::getId, result -> result)); + List resultVertices = graph.getVertices(vertexIds.keySet().toArray()); + List headers = resultVertices.parallelStream().map(v -> { + try { + return enrichVertex(ret, resultAttributes, vertexIds.get(v.getId()), v, fetchCollapsedResults); + } catch (AtlasBaseException e) { + throw new RuntimeException(e); + } + }).collect(Collectors.toList()); + headers.forEach(ret::addEntity); + } } catch (Exception e) { throw e; }