Search in sources :

Example 11 with LineageRelation

use of org.apache.atlas.model.lineage.AtlasLineageInfo.LineageRelation in project incubator-atlas by apache.

the class QuickStartV2 method lineage.

private void lineage() throws AtlasServiceException {
    System.out.println("\nSample Lineage Info: ");
    AtlasLineageInfo lineageInfo = atlasClientV2.getLineageInfo(getTableId(SALES_FACT_DAILY_MV_TABLE), LineageDirection.BOTH, 0);
    Set<LineageRelation> relations = lineageInfo.getRelations();
    Map<String, AtlasEntityHeader> guidEntityMap = lineageInfo.getGuidEntityMap();
    for (LineageRelation relation : relations) {
        AtlasEntityHeader fromEntity = guidEntityMap.get(relation.getFromEntityId());
        AtlasEntityHeader toEntity = guidEntityMap.get(relation.getToEntityId());
        System.out.println(fromEntity.getDisplayText() + "(" + fromEntity.getTypeName() + ") -> " + toEntity.getDisplayText() + "(" + toEntity.getTypeName() + ")");
    }
}
Also used : AtlasLineageInfo(org.apache.atlas.model.lineage.AtlasLineageInfo) LineageRelation(org.apache.atlas.model.lineage.AtlasLineageInfo.LineageRelation) AtlasEntityHeader(org.apache.atlas.model.instance.AtlasEntityHeader)

Example 12 with LineageRelation

use of org.apache.atlas.model.lineage.AtlasLineageInfo.LineageRelation in project incubator-atlas by apache.

the class EntityLineageService method getLineageInfo.

private AtlasLineageInfo getLineageInfo(String guid, LineageDirection direction, int depth) throws AtlasBaseException {
    Map<String, AtlasEntityHeader> entities = new HashMap<>();
    Set<LineageRelation> relations = new HashSet<>();
    String lineageQuery = getLineageQuery(guid, direction, depth);
    List paths = (List) graph.executeGremlinScript(lineageQuery, true);
    if (CollectionUtils.isNotEmpty(paths)) {
        for (Object path : paths) {
            if (path instanceof List) {
                List vertices = (List) path;
                if (CollectionUtils.isNotEmpty(vertices)) {
                    AtlasEntityHeader prev = null;
                    for (Object vertex : vertices) {
                        if (!(vertex instanceof AtlasVertex)) {
                            continue;
                        }
                        AtlasEntityHeader entity = entityRetriever.toAtlasEntityHeader((AtlasVertex) vertex);
                        if (!entities.containsKey(entity.getGuid())) {
                            entities.put(entity.getGuid(), entity);
                        }
                        if (prev != null) {
                            if (direction.equals(LineageDirection.INPUT)) {
                                relations.add(new LineageRelation(entity.getGuid(), prev.getGuid()));
                            } else if (direction.equals(LineageDirection.OUTPUT)) {
                                relations.add(new LineageRelation(prev.getGuid(), entity.getGuid()));
                            }
                        }
                        prev = entity;
                    }
                }
            }
        }
    }
    return new AtlasLineageInfo(guid, entities, relations, direction, depth);
}
Also used : AtlasLineageInfo(org.apache.atlas.model.lineage.AtlasLineageInfo) AtlasVertex(org.apache.atlas.repository.graphdb.AtlasVertex) HashMap(java.util.HashMap) LineageRelation(org.apache.atlas.model.lineage.AtlasLineageInfo.LineageRelation) AtlasEntityHeader(org.apache.atlas.model.instance.AtlasEntityHeader) List(java.util.List) HashSet(java.util.HashSet)

Aggregations

AtlasEntityHeader (org.apache.atlas.model.instance.AtlasEntityHeader)12 LineageRelation (org.apache.atlas.model.lineage.AtlasLineageInfo.LineageRelation)12 AtlasLineageInfo (org.apache.atlas.model.lineage.AtlasLineageInfo)11 Test (org.testng.annotations.Test)7 BaseRepositoryTest (org.apache.atlas.BaseRepositoryTest)5 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 List (java.util.List)2 AtlasVertex (org.apache.atlas.repository.graphdb.AtlasVertex)2 Map (java.util.Map)1 EntityResult (org.apache.atlas.model.legacy.EntityResult)1 AtlasEdge (org.apache.atlas.repository.graphdb.AtlasEdge)1