diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index de25ae312c..741f59f263 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -1,3 +1,4 @@ + # # Licensed to the Apache Software Foundation (ASF) under one # or more contributor license agreements. See the NOTICE file diff --git a/repository/src/main/java/org/apache/atlas/repository/graph/GraphHelper.java b/repository/src/main/java/org/apache/atlas/repository/graph/GraphHelper.java index 5da3dca267..5a572a7cfa 100755 --- a/repository/src/main/java/org/apache/atlas/repository/graph/GraphHelper.java +++ b/repository/src/main/java/org/apache/atlas/repository/graph/GraphHelper.java @@ -33,6 +33,7 @@ import org.apache.atlas.model.instance.AtlasEntityHeader; import org.apache.atlas.model.instance.AtlasObjectId; import org.apache.atlas.model.instance.AtlasRelationship; +import org.apache.atlas.repository.graphdb.janus.AtlasJanusEdge; import org.apache.atlas.repository.store.graph.v2.AtlasGraphUtilsV2; import org.apache.atlas.repository.store.graph.v2.TransactionInterceptHelper; import org.apache.atlas.type.AtlasArrayType; @@ -2025,6 +2026,27 @@ public static Iterator getActiveEdges(AtlasVertex vertex, String chil } } + /** + * Get all the active edges + * @param vertex entity vertex + * @return Iterator of children edges + */ + public static Iterator getOnlyActiveEdges(AtlasVertex vertex, AtlasEdgeDirection direction) throws AtlasBaseException { + AtlasPerfMetrics.MetricRecorder metricRecorder = RequestContext.get().startMetricRecord("GraphHelper.getOnlyActiveEdges"); + + try { + return vertex.query() + .direction(direction) + .has(STATE_PROPERTY_KEY, ACTIVE_STATE_VALUE) + .edges() + .iterator(); + } catch (Exception e) { + throw new AtlasBaseException(AtlasErrorCode.INTERNAL_ERROR, e); + } + finally { + RequestContext.get().endMetricRecord(metricRecorder); + } + } public static Iterator getActiveVertices(AtlasVertex vertex, String childrenEdgeLabel, AtlasEdgeDirection direction) throws AtlasBaseException { AtlasPerfMetrics.MetricRecorder metricRecorder = RequestContext.get().startMetricRecord("CategoryPreProcessor.getEdges"); diff --git a/repository/src/main/java/org/apache/atlas/repository/store/graph/v2/EntityGraphRetriever.java b/repository/src/main/java/org/apache/atlas/repository/store/graph/v2/EntityGraphRetriever.java index 76c9fd7ae5..fdcb7877e0 100644 --- a/repository/src/main/java/org/apache/atlas/repository/store/graph/v2/EntityGraphRetriever.java +++ b/repository/src/main/java/org/apache/atlas/repository/store/graph/v2/EntityGraphRetriever.java @@ -285,6 +285,8 @@ public AtlasObjectId toAtlasObjectId(AtlasVertex entityVertex) throws AtlasBaseE if (entityType != null) { Map uniqueAttributes = new HashMap<>(); + Map attributes = new HashMap<>(); + Set relationAttributes = RequestContext.get().getRelationAttrsForSearch(); for (AtlasAttribute attribute : entityType.getUniqAttributes().values()) { Object attrValue = getVertexAttribute(entityVertex, attribute); @@ -294,18 +296,13 @@ public AtlasObjectId toAtlasObjectId(AtlasVertex entityVertex) throws AtlasBaseE } } - Map attributes = new HashMap<>(); - Set relationAttributes = RequestContext.get().getRelationAttrsForSearch(); - - // preloadProperties here if (CollectionUtils.isNotEmpty(relationAttributes)) { - Map referenceVertexProperties = preloadProperties(entityVertex, entityType, Collections.emptySet()); for (String attributeName : relationAttributes) { AtlasAttribute attribute = entityType.getAttribute(attributeName); if (attribute != null && !uniqueAttributes.containsKey(attributeName)) { - Object attrValue = getVertexAttributePreFetchCache(entityVertex, attribute, referenceVertexProperties); + Object attrValue = getVertexAttribute(entityVertex, attribute); if (attrValue != null) { attributes.put(attribute.getName(), attrValue); } @@ -1003,29 +1000,13 @@ private AtlasEntityHeader mapVertexToAtlasEntityHeader(AtlasVertex entityVertex) return mapVertexToAtlasEntityHeader(entityVertex, Collections.emptySet()); } - private Map preloadProperties(AtlasVertex entityVertex, AtlasEntityType entityType, Set attributes) { + private Map preloadProperties(AtlasVertex entityVertex, AtlasEntityType entityType, Set attributes) throws AtlasBaseException { Map propertiesMap = new HashMap<>(); - String guid = entityVertex.getProperty(Constants.GUID_PROPERTY_KEY, String.class); + // Execute the traversal to fetch properties Iterator> traversal = ((AtlasJanusVertex)entityVertex).getWrappedElement().properties(); - // Fetch edges in both directions - Iterator edges = entityVertex.getEdges(AtlasEdgeDirection.BOTH).iterator(); - List edgeLabelsDebug = new ArrayList<>(); - while (edges.hasNext()) { - AtlasJanusEdge edge = edges.next(); - edgeLabelsDebug.add(edge.getLabel()); - } - - Set edgeLabels = - edgeLabelsDebug.stream() - .map(edgeLabel -> { - Optional matchingAttrOpt = attributes.stream().filter(ele -> edgeLabel.contains(ele)).findFirst(); - return matchingAttrOpt.orElse(null); - }).filter(Objects::nonNull) - .collect(Collectors.toSet()); - - edgeLabels.stream().forEach(e -> propertiesMap.put(e, StringUtils.SPACE)); + retrieveEdgeLabels(entityVertex, AtlasEdgeDirection.BOTH, attributes, propertiesMap); // Iterate through the resulting VertexProperty objects while (traversal.hasNext()) { @@ -1058,6 +1039,27 @@ private Map preloadProperties(AtlasVertex entityVertex, AtlasEnt return propertiesMap; } + private void retrieveEdgeLabels(AtlasVertex entityVertex, AtlasEdgeDirection edgeDirection, Set attributes, Map propertiesMap) throws AtlasBaseException { + Iterator edges = GraphHelper.getOnlyActiveEdges(entityVertex, edgeDirection); + + + List edgeLabelsDebug = new ArrayList<>(); + while (edges.hasNext()) { + AtlasJanusEdge edge = edges.next(); + edgeLabelsDebug.add(edge.getLabel()); + } + + Set edgeLabels = + edgeLabelsDebug.stream() + .map(edgeLabel -> { + Optional matchingAttrOpt = attributes.stream().filter(ele -> (edgeLabel.contains(ele))).findFirst(); + return matchingAttrOpt.orElse(null); + }).filter(Objects::nonNull) + .collect(Collectors.toSet()); + + edgeLabels.stream().forEach(e -> propertiesMap.put(e, StringUtils.SPACE)); + } + private void updateAttrValue( Map propertiesMap, VertexProperty property){ Object value = propertiesMap.get(property.key()); if (value instanceof List) { @@ -1930,7 +1932,8 @@ public Object getVertexAttributePreFetchCache(AtlasVertex vertex, AtlasAttribute } // value is present as marker or is inward relation, fetch the value from the vertex - if (properties.get(attribute.getName()) == StringUtils.SPACE || AtlasRelationshipEdgeDirection.IN.equals(attribute.getRelationshipEdgeDirection())) { + if (properties.get(attribute.getName()) == StringUtils.SPACE || AtlasRelationshipEdgeDirection.IN.equals(attribute.getRelationshipEdgeDirection()) + || AtlasRelationshipEdgeDirection.OUT.equals(attribute.getRelationshipEdgeDirection())) { return mapVertexToAttribute(vertex, attribute, null, false); }