You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@atlas.apache.org by sa...@apache.org on 2020/06/29 22:55:49 UTC
[atlas] branch master updated: ATLAS-3866 : Relationship search API
for hive storage desc throws error code 500
This is an automated email from the ASF dual-hosted git repository.
sarath pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/atlas.git
The following commit(s) were added to refs/heads/master by this push:
new 0221e3d ATLAS-3866 : Relationship search API for hive storage desc throws error code 500
0221e3d is described below
commit 0221e3dd297057dab344b8d9b6672a37adafabbc
Author: Pinal Shah <pi...@freestoneinfotech.com>
AuthorDate: Mon Jun 29 10:04:26 2020 +0530
ATLAS-3866 : Relationship search API for hive storage desc throws error code 500
Signed-off-by: Sarath Subramanian <sa...@apache.org>
---
.../atlas/discovery/EntityDiscoveryService.java | 50 ++++++++++++++++++----
1 file changed, 42 insertions(+), 8 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 b2737af..4169e14 100644
--- a/repository/src/main/java/org/apache/atlas/discovery/EntityDiscoveryService.java
+++ b/repository/src/main/java/org/apache/atlas/discovery/EntityDiscoveryService.java
@@ -63,14 +63,13 @@ import javax.script.ScriptEngine;
import javax.script.ScriptException;
import java.util.*;
-import static org.apache.atlas.AtlasErrorCode.CLASSIFICATION_NOT_FOUND;
-import static org.apache.atlas.AtlasErrorCode.DISCOVERY_QUERY_FAILED;
-import static org.apache.atlas.AtlasErrorCode.UNKNOWN_TYPENAME;
+import static org.apache.atlas.AtlasErrorCode.*;
import static org.apache.atlas.SortOrder.ASCENDING;
import static org.apache.atlas.SortOrder.DESCENDING;
import static org.apache.atlas.model.instance.AtlasEntity.Status.ACTIVE;
import static org.apache.atlas.model.instance.AtlasEntity.Status.DELETED;
-import static org.apache.atlas.repository.Constants.*;
+import static org.apache.atlas.repository.Constants.ASSET_ENTITY_TYPE;
+import static org.apache.atlas.repository.Constants.OWNER_ATTRIBUTE;
import static org.apache.atlas.util.AtlasGremlinQueryProvider.AtlasGremlinQuery.*;
@Component
@@ -564,7 +563,7 @@ public class EntityDiscoveryService implements AtlasDiscoveryService {
@Override
@GraphTransaction
- public AtlasSearchResult searchRelatedEntities(String guid, String relation, String sortByAttributeName, SortOrder sortOrder,
+ public AtlasSearchResult searchRelatedEntities(String guid, String relation, String sortBy, SortOrder sortOrder,
boolean excludeDeletedEntities, int limit, int offset) throws AtlasBaseException {
AtlasSearchResult ret = new AtlasSearchResult(AtlasQueryType.RELATIONSHIP);
@@ -594,15 +593,50 @@ public class EntityDiscoveryService implements AtlasDiscoveryService {
}
}
- if (StringUtils.isEmpty(sortByAttributeName)) {
- sortByAttributeName = DEFAULT_SORT_ATTRIBUTE_NAME;
+ String sortByAttributeName = DEFAULT_SORT_ATTRIBUTE_NAME;
+
+ if (StringUtils.isNotEmpty(sortBy)) {
+ sortByAttributeName = sortBy;
+ }
+
+ //get entity type of relationship (End vertex entity type) from relationship label
+ Iterator<AtlasEdge> edges = GraphHelper.getAdjacentEdgesByLabel(entityVertex, AtlasEdgeDirection.BOTH, relation);
+ AtlasEntityType endEntityType = null;
+
+ if (edges != null && edges.hasNext()) {
+ AtlasEdge relationEdge = edges.next();
+ AtlasVertex outVertex = relationEdge.getOutVertex();
+ AtlasVertex inVertex = relationEdge.getInVertex();
+ String outVertexId = outVertex != null ? outVertex.getIdForDisplay() : null;
+ AtlasVertex endVertex = StringUtils.equals(outVertexId, entityVertex.getIdForDisplay()) ? inVertex : outVertex;
+ String endTypeName = GraphHelper.getTypeName(endVertex);
+
+ endEntityType = typeRegistry.getEntityTypeByName(endTypeName);
+ }
+
+ if (endEntityType == null) {
+ ret.setEntities(new ArrayList<>());
+
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("Invalid relation : {} ", relation);
+ }
+
+ return ret;
}
- AtlasAttribute sortByAttribute = entityType.getAttribute(sortByAttributeName);
+ AtlasAttribute sortByAttribute = endEntityType.getAttribute(sortByAttributeName);
if (sortByAttribute == null) {
sortByAttributeName = null;
sortOrder = null;
+
+ if (LOG.isDebugEnabled()) {
+ if (StringUtils.isNotEmpty(sortBy)) {
+ LOG.debug("Invalid sortBy Attribute {} for entityType {}, Ignoring Sorting", sortBy, endEntityType.getTypeName());
+ } else {
+ LOG.debug("Invalid Default sortBy Attribute {} for entityType {}, Ignoring Sorting", DEFAULT_SORT_ATTRIBUTE_NAME, endEntityType.getTypeName());
+ }
+ }
} else {
sortByAttributeName = sortByAttribute.getVertexPropertyName();