private List<Object> mapVertexToArray(AtlasVertex entityVertex, AtlasEntityExtInfo entityExtInfo, boolean isOwnedAttribute, AtlasAttribute attribute, final boolean isMinExtInfo) throws AtlasBaseException { AtlasArrayType arrayType = (AtlasArrayType) attribute.getAttributeType(); AtlasType arrayElementType = arrayType.getElementType(); List<Object> arrayElements = getArrayElementsProperty(arrayElementType, entityVertex, attribute); if (CollectionUtils.isEmpty(arrayElements)) { return null; } if (LOG.isDebugEnabled()) { LOG.debug("Mapping array attribute {} for vertex {}", arrayElementType.getTypeName(), entityVertex); } List arrValues = new ArrayList(arrayElements.size()); String edgeLabel = attribute.getRelationshipEdgeLabel(); AtlasRelationshipEdgeDirection edgeDirection = attribute.getRelationshipEdgeDirection(); for (Object element : arrayElements) { // When internal types are deleted, sometimes the collection type attribute will contain a null value // Graph layer does erroneous mapping of the null element, hence avoiding the processing of the null element if (element == null) { LOG.debug("Skipping null arrayElement"); continue; } Object arrValue = mapVertexToCollectionEntry(entityVertex, arrayElementType, element, edgeLabel, entityExtInfo, isOwnedAttribute, edgeDirection, isMinExtInfo); if (arrValue != null) { arrValues.add(arrValue); } } return arrValues; }
private List<Object> mapVertexToArray(AtlasVertex entityVertex, AtlasEntityExtInfo entityExtInfo, boolean isOwnedAttribute, AtlasAttribute attribute, final boolean isMinExtInfo) throws AtlasBaseException { AtlasArrayType arrayType = (AtlasArrayType) attribute.getAttributeType(); AtlasType arrayElementType = arrayType.getElementType(); List<Object> arrayElements = getArrayElementsProperty(arrayElementType, entityVertex, attribute); if (CollectionUtils.isEmpty(arrayElements)) { return null; } if (LOG.isDebugEnabled()) { LOG.debug("Mapping array attribute {} for vertex {}", arrayElementType.getTypeName(), entityVertex); } List arrValues = new ArrayList(arrayElements.size()); String edgeLabel = attribute.getRelationshipEdgeLabel(); AtlasRelationshipEdgeDirection edgeDirection = attribute.getRelationshipEdgeDirection(); for (Object element : arrayElements) { // When internal types are deleted, sometimes the collection type attribute will contain a null value // Graph layer does erroneous mapping of the null element, hence avoiding the processing of the null element if (element == null) { LOG.debug("Skipping null arrayElement"); continue; } Object arrValue = mapVertexToCollectionEntry(entityVertex, arrayElementType, element, edgeLabel, entityExtInfo, isOwnedAttribute, edgeDirection, isMinExtInfo); if (arrValue != null) { arrValues.add(arrValue); } } return arrValues; }
private List<AtlasVertex> getAssignedEntities(AtlasVertex glossaryTerm) { List<AtlasVertex> ret = new ArrayList<>(); AtlasEntityType termType = getTermEntityType(); AtlasAttribute attr = termType.getRelationshipAttribute(TermSearchProcessor.ATLAS_GLOSSARY_TERM_ATTR_ASSIGNED_ENTITIES); Iterator<AtlasEdge> edges = GraphHelper.getEdgesForLabel(glossaryTerm, attr.getRelationshipEdgeLabel(), attr.getRelationshipEdgeDirection()); boolean excludeDeletedEntities = searchParameters.getExcludeDeletedEntities(); if (edges != null) { while (edges.hasNext()) { AtlasEdge edge = edges.next(); AtlasVertex inVertex = edge.getInVertex(); if (excludeDeletedEntities && AtlasGraphUtilsV2.getState(inVertex) == AtlasEntity.Status.DELETED) { continue; } ret.add(inVertex); } } return ret; }
private void addInverseReference(EntityMutationContext context, AtlasAttribute inverseAttribute, AtlasEdge edge, Map<String, Object> relationshipAttributes) throws AtlasBaseException { AtlasStructType inverseType = inverseAttribute.getDefinedInType(); AtlasVertex inverseVertex = edge.getInVertex(); String inverseEdgeLabel = inverseAttribute.getRelationshipEdgeLabel(); AtlasEdge inverseEdge = graphHelper.getEdgeForLabel(inverseVertex, inverseEdgeLabel); String propertyName = AtlasGraphUtilsV2.getQualifiedAttributePropertyKey(inverseType, inverseAttribute.getName());
private Map<String, Object> mapVertexToMap(AtlasVertex entityVertex, AtlasEntityExtInfo entityExtInfo, boolean isOwnedAttribute, AtlasAttribute attribute, final boolean isMinExtInfo) throws AtlasBaseException { Map<String, Object> ret = null; AtlasMapType mapType = (AtlasMapType) attribute.getAttributeType(); AtlasType mapValueType = mapType.getValueType(); if (LOG.isDebugEnabled()) { LOG.debug("Mapping map attribute {} for vertex {}", mapType.getTypeName(), entityVertex); } if (isReference(mapValueType)) { Map<String, Object> currentMap = getReferenceMap(entityVertex, attribute); if (MapUtils.isNotEmpty(currentMap)) { ret = new HashMap<>(); for (Map.Entry<String, Object> entry : currentMap.entrySet()) { String mapKey = entry.getKey(); Object keyValue = entry.getValue(); Object mapValue = mapVertexToCollectionEntry(entityVertex, mapValueType, keyValue, attribute.getRelationshipEdgeLabel(), entityExtInfo, isOwnedAttribute, attribute.getRelationshipEdgeDirection(), isMinExtInfo); if (mapValue != null) { ret.put(mapKey, mapValue); } } } } else { ret = getPrimitiveMap(entityVertex, attribute.getVertexPropertyName()); } if (MapUtils.isEmpty(ret)) { ret = null; } return ret; }
public AtlasAttribute(AtlasStructType definedInType, AtlasAttributeDef attrDef, AtlasType attributeType, String relationshipLabel) { this.definedInType = definedInType; this.attributeDef = attrDef; this.attributeType = attributeType.getTypeForAttribute(); this.qualifiedName = getQualifiedAttributeName(definedInType.getStructDef(), attributeDef.getName()); this.vertexPropertyName = encodePropertyKey(this.qualifiedName); this.relationshipEdgeLabel = getRelationshipEdgeLabel(relationshipLabel); boolean isOwnedRef = false; String inverseRefAttribute = null; if (CollectionUtils.isNotEmpty(attributeDef.getConstraints())) { for (AtlasConstraintDef constraint : attributeDef.getConstraints()) { if (constraint.isConstraintType(CONSTRAINT_TYPE_OWNED_REF)) { isOwnedRef = true; } if (constraint.isConstraintType(CONSTRAINT_TYPE_INVERSE_REF)) { Object val = constraint.getParam(CONSTRAINT_PARAM_ATTRIBUTE); if (val != null) { inverseRefAttribute = val.toString(); } } } } this.isOwnedRef = isOwnedRef; this.inverseRefAttributeName = inverseRefAttribute; this.relationshipEdgeDirection = AtlasRelationshipEdgeDirection.OUT; }
private Map<String, Object> mapVertexToMap(AtlasVertex entityVertex, AtlasEntityExtInfo entityExtInfo, boolean isOwnedAttribute, AtlasAttribute attribute, final boolean isMinExtInfo) throws AtlasBaseException { Map<String, Object> ret = null; AtlasMapType mapType = (AtlasMapType) attribute.getAttributeType(); AtlasType mapValueType = mapType.getValueType(); if (LOG.isDebugEnabled()) { LOG.debug("Mapping map attribute {} for vertex {}", mapType.getTypeName(), entityVertex); } if (isReference(mapValueType)) { Map<String, Object> currentMap = getReferenceMap(entityVertex, attribute); if (MapUtils.isNotEmpty(currentMap)) { ret = new HashMap<>(); for (Map.Entry<String, Object> entry : currentMap.entrySet()) { String mapKey = entry.getKey(); Object keyValue = entry.getValue(); Object mapValue = mapVertexToCollectionEntry(entityVertex, mapValueType, keyValue, attribute.getRelationshipEdgeLabel(), entityExtInfo, isOwnedAttribute, attribute.getRelationshipEdgeDirection(), isMinExtInfo); if (mapValue != null) { ret.put(mapKey, mapValue); } } } } else { ret = getPrimitiveMap(entityVertex, attribute.getVertexPropertyName()); } if (MapUtils.isEmpty(ret)) { ret = null; } return ret; }
private String getRelationshipEdgeLabel(AtlasVertex fromVertex, AtlasVertex toVertex, String relationshipTypeName) { if (LOG.isDebugEnabled()) { LOG.debug("getRelationshipEdgeLabel({})", relationshipTypeName); } AtlasRelationshipType relationshipType = typeRegistry.getRelationshipTypeByName(relationshipTypeName); String ret = relationshipType.getRelationshipDef().getRelationshipLabel(); AtlasRelationshipEndDef endDef1 = relationshipType.getRelationshipDef().getEndDef1(); AtlasRelationshipEndDef endDef2 = relationshipType.getRelationshipDef().getEndDef2(); Set<String> fromVertexTypes = getTypeAndAllSuperTypes(AtlasGraphUtilsV2.getTypeName(fromVertex)); Set<String> toVertexTypes = getTypeAndAllSuperTypes(AtlasGraphUtilsV2.getTypeName(toVertex)); AtlasAttribute attribute = null; // validate entity type and all its supertypes contains relationshipDefs end type // e.g. [hive_process -> hive_table] -> [Process -> DataSet] if (fromVertexTypes.contains(endDef1.getType()) && toVertexTypes.contains(endDef2.getType())) { String attributeName = endDef1.getName(); attribute = relationshipType.getEnd1Type().getRelationshipAttribute(attributeName); } else if (fromVertexTypes.contains(endDef2.getType()) && toVertexTypes.contains(endDef1.getType())) { String attributeName = endDef2.getName(); attribute = relationshipType.getEnd2Type().getRelationshipAttribute(attributeName); } if (attribute != null) { ret = attribute.getRelationshipEdgeLabel(); } return ret; }
public AtlasAttribute(AtlasStructType definedInType, AtlasAttributeDef attrDef, AtlasType attributeType, String relationshipLabel) { this.definedInType = definedInType; this.attributeDef = attrDef; this.attributeType = attributeType.getTypeForAttribute(); this.qualifiedName = getQualifiedAttributeName(definedInType.getStructDef(), attributeDef.getName()); this.vertexPropertyName = encodePropertyKey(this.qualifiedName); this.relationshipEdgeLabel = getRelationshipEdgeLabel(relationshipLabel); boolean isOwnedRef = false; String inverseRefAttribute = null; if (CollectionUtils.isNotEmpty(attributeDef.getConstraints())) { for (AtlasConstraintDef constraint : attributeDef.getConstraints()) { if (constraint.isConstraintType(CONSTRAINT_TYPE_OWNED_REF)) { isOwnedRef = true; } if (constraint.isConstraintType(CONSTRAINT_TYPE_INVERSE_REF)) { Object val = constraint.getParam(CONSTRAINT_PARAM_ATTRIBUTE); if (val != null) { inverseRefAttribute = val.toString(); } } } } this.isOwnedRef = isOwnedRef; this.inverseRefAttributeName = inverseRefAttribute; this.relationshipEdgeDirection = AtlasRelationshipEdgeDirection.OUT; }
private String getRelationshipEdgeLabel(AtlasVertex fromVertex, AtlasVertex toVertex, String relationshipTypeName) { if (LOG.isDebugEnabled()) { LOG.debug("getRelationshipEdgeLabel({})", relationshipTypeName); } AtlasRelationshipType relationshipType = typeRegistry.getRelationshipTypeByName(relationshipTypeName); String ret = relationshipType.getRelationshipDef().getRelationshipLabel(); AtlasRelationshipEndDef endDef1 = relationshipType.getRelationshipDef().getEndDef1(); AtlasRelationshipEndDef endDef2 = relationshipType.getRelationshipDef().getEndDef2(); Set<String> fromVertexTypes = getTypeAndAllSuperTypes(AtlasGraphUtilsV2.getTypeName(fromVertex)); Set<String> toVertexTypes = getTypeAndAllSuperTypes(AtlasGraphUtilsV2.getTypeName(toVertex)); AtlasAttribute attribute = null; // validate entity type and all its supertypes contains relationshipDefs end type // e.g. [hive_process -> hive_table] -> [Process -> DataSet] if (fromVertexTypes.contains(endDef1.getType()) && toVertexTypes.contains(endDef2.getType())) { String attributeName = endDef1.getName(); attribute = relationshipType.getEnd1Type().getRelationshipAttribute(attributeName); } else if (fromVertexTypes.contains(endDef2.getType()) && toVertexTypes.contains(endDef1.getType())) { String attributeName = endDef2.getName(); attribute = relationshipType.getEnd2Type().getRelationshipAttribute(attributeName); } if (attribute != null) { ret = attribute.getRelationshipEdgeLabel(); } return ret; }
private List<AtlasRelatedObjectId> mapRelationshipArrayAttribute(AtlasVertex entityVertex, AtlasAttribute attribute) throws AtlasBaseException { List<AtlasRelatedObjectId> ret = new ArrayList<>(); Iterator<AtlasEdge> edges = null; if (attribute.getRelationshipEdgeDirection() == IN) { edges = getIncomingEdgesByLabel(entityVertex, attribute.getRelationshipEdgeLabel()); } else if (attribute.getRelationshipEdgeDirection() == OUT) { edges = getOutGoingEdgesByLabel(entityVertex, attribute.getRelationshipEdgeLabel()); } else if (attribute.getRelationshipEdgeDirection() == BOTH) { edges = getAdjacentEdgesByLabel(entityVertex, AtlasEdgeDirection.BOTH, attribute.getRelationshipEdgeLabel()); } if (edges != null) { while (edges.hasNext()) { AtlasEdge relationshipEdge = edges.next(); AtlasRelatedObjectId relatedObjectId = mapVertexToRelatedObjectId(entityVertex, relationshipEdge); ret.add(relatedObjectId); } } return ret; }
private String getRelationshipEdgeLabel(String typeName, String relationshipTypeName) { AtlasRelationshipType relationshipType = typeRegistry.getRelationshipTypeByName(relationshipTypeName); AtlasRelationshipDef relationshipDef = relationshipType.getRelationshipDef(); AtlasEntityType end1Type = relationshipType.getEnd1Type(); AtlasEntityType end2Type = relationshipType.getEnd2Type(); Set<String> vertexTypes = getTypeAndAllSuperTypes(typeName); AtlasAttribute attribute = null; if (vertexTypes.contains(end1Type.getTypeName())) { String attributeName = relationshipDef.getEndDef1().getName(); attribute = (attributeName != null) ? end1Type.getAttribute(attributeName) : null; } else if (vertexTypes.contains(end2Type.getTypeName())) { String attributeName = relationshipDef.getEndDef2().getName(); attribute = (attributeName != null) ? end2Type.getAttribute(attributeName) : null; } return (attribute != null) ? attribute.getRelationshipEdgeLabel() : null; } }
private List<AtlasRelatedObjectId> mapRelationshipArrayAttribute(AtlasVertex entityVertex, AtlasAttribute attribute) throws AtlasBaseException { List<AtlasRelatedObjectId> ret = new ArrayList<>(); Iterator<AtlasEdge> edges = null; if (attribute.getRelationshipEdgeDirection() == IN) { edges = getIncomingEdgesByLabel(entityVertex, attribute.getRelationshipEdgeLabel()); } else if (attribute.getRelationshipEdgeDirection() == OUT) { edges = getOutGoingEdgesByLabel(entityVertex, attribute.getRelationshipEdgeLabel()); } else if (attribute.getRelationshipEdgeDirection() == BOTH) { edges = getAdjacentEdgesByLabel(entityVertex, AtlasEdgeDirection.BOTH, attribute.getRelationshipEdgeLabel()); } if (edges != null) { while (edges.hasNext()) { AtlasEdge relationshipEdge = edges.next(); AtlasRelatedObjectId relatedObjectId = mapVertexToRelatedObjectId(entityVertex, relationshipEdge); ret.add(relatedObjectId); } } return ret; }
private String getRelationshipEdgeLabel(String typeName, String relationshipTypeName) { AtlasRelationshipType relationshipType = typeRegistry.getRelationshipTypeByName(relationshipTypeName); AtlasRelationshipDef relationshipDef = relationshipType.getRelationshipDef(); AtlasEntityType end1Type = relationshipType.getEnd1Type(); AtlasEntityType end2Type = relationshipType.getEnd2Type(); Set<String> vertexTypes = getTypeAndAllSuperTypes(typeName); AtlasAttribute attribute = null; if (vertexTypes.contains(end1Type.getTypeName())) { String attributeName = relationshipDef.getEndDef1().getName(); attribute = (attributeName != null) ? end1Type.getAttribute(attributeName) : null; } else if (vertexTypes.contains(end2Type.getTypeName())) { String attributeName = relationshipDef.getEndDef2().getName(); attribute = (attributeName != null) ? end2Type.getAttribute(attributeName) : null; } return (attribute != null) ? attribute.getRelationshipEdgeLabel() : null; }
@Override public String getRelationshipEdgeLabel(GremlinQueryComposer.Context context, String attributeName) { AtlasEntityType et = context.getActiveEntityType(); if(et == null) { return ""; } AtlasStructType.AtlasAttribute attr = et.getAttribute(attributeName); return (attr != null) ? attr.getRelationshipEdgeLabel() : ""; }
@Override public String getRelationshipEdgeLabel(GremlinQueryComposer.Context context, String attributeName) { AtlasEntityType et = context.getActiveEntityType(); if(et == null) { return ""; } AtlasStructType.AtlasAttribute attr = et.getAttribute(attributeName); return (attr != null) ? attr.getRelationshipEdgeLabel() : ""; }
public static List<AtlasEdge> getCollectionElementsUsingRelationship(AtlasVertex vertex, AtlasAttribute attribute) { List<AtlasEdge> ret; String edgeLabel = attribute.getRelationshipEdgeLabel(); AtlasRelationshipEdgeDirection edgeDirection = attribute.getRelationshipEdgeDirection(); Iterator<AtlasEdge> edgesForLabel = getEdgesForLabel(vertex, edgeLabel, edgeDirection); ret = IteratorUtils.toList(edgesForLabel); sortCollectionElements(attribute, ret); return ret; }
public static List<AtlasEdge> getMapValuesUsingRelationship(AtlasVertex vertex, AtlasAttribute attribute) { String edgeLabel = attribute.getRelationshipEdgeLabel(); AtlasRelationshipEdgeDirection edgeDirection = attribute.getRelationshipEdgeDirection(); Iterator<AtlasEdge> edgesForLabel = getEdgesForLabel(vertex, edgeLabel, edgeDirection); return (List<AtlasEdge>) IteratorUtils.toList(edgesForLabel); }
private AtlasObjectId mapRelatedVertexToObjectId(AtlasVertex entityVertex, AtlasAttribute attribute) throws AtlasBaseException { AtlasEdge edge = graphHelper.getEdgeForLabel(entityVertex, attribute.getRelationshipEdgeLabel(), attribute.getRelationshipEdgeDirection()); return mapVertexToRelatedObjectId(entityVertex, edge); }
private AtlasObjectId mapRelatedVertexToObjectId(AtlasVertex entityVertex, AtlasAttribute attribute) throws AtlasBaseException { AtlasEdge edge = graphHelper.getEdgeForLabel(entityVertex, attribute.getRelationshipEdgeLabel(), attribute.getRelationshipEdgeDirection()); return mapVertexToRelatedObjectId(entityVertex, edge); }