Search in sources :

Example 6 with LineageRelation

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

the class QuickStartV2IT method testLineageIsMaintained.

@Test
public void testLineageIsMaintained() throws AtlasServiceException, JSONException {
    String salesFactTableId = getTableId(QuickStartV2.SALES_FACT_TABLE);
    String timeDimTableId = getTableId(QuickStartV2.TIME_DIM_TABLE);
    String salesFactDailyMVId = getTableId(QuickStartV2.SALES_FACT_DAILY_MV_TABLE);
    String salesFactMonthlyMvId = getTableId(QuickStartV2.SALES_FACT_MONTHLY_MV_TABLE);
    String salesDailyProcessId = getProcessId(QuickStartV2.LOAD_SALES_DAILY_PROCESS);
    String salesMonthlyProcessId = getProcessId(QuickStartV2.LOAD_SALES_MONTHLY_PROCESS);
    AtlasLineageInfo inputLineage = atlasClientV2.getLineageInfo(salesFactDailyMVId, LineageDirection.BOTH, 0);
    List<LineageRelation> relations = new ArrayList<>(inputLineage.getRelations());
    Map<String, AtlasEntityHeader> entityMap = inputLineage.getGuidEntityMap();
    assertEquals(relations.size(), 5);
    assertEquals(entityMap.size(), 6);
    assertTrue(entityMap.containsKey(salesFactTableId));
    assertTrue(entityMap.containsKey(timeDimTableId));
    assertTrue(entityMap.containsKey(salesFactDailyMVId));
    assertTrue(entityMap.containsKey(salesDailyProcessId));
    assertTrue(entityMap.containsKey(salesFactMonthlyMvId));
    assertTrue(entityMap.containsKey(salesMonthlyProcessId));
}
Also used : AtlasLineageInfo(org.apache.atlas.model.lineage.AtlasLineageInfo) LineageRelation(org.apache.atlas.model.lineage.AtlasLineageInfo.LineageRelation) ArrayList(java.util.ArrayList) AtlasEntityHeader(org.apache.atlas.model.instance.AtlasEntityHeader) Test(org.testng.annotations.Test)

Example 7 with LineageRelation

use of org.apache.atlas.model.lineage.AtlasLineageInfo.LineageRelation in project 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 8 with LineageRelation

use of org.apache.atlas.model.lineage.AtlasLineageInfo.LineageRelation in project 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 edgeMapList = (List) graph.executeGremlinScript(lineageQuery, false);
    if (CollectionUtils.isNotEmpty(edgeMapList)) {
        for (Object edgeMap : edgeMapList) {
            if (edgeMap instanceof Map) {
                for (final Object o : ((Map) edgeMap).entrySet()) {
                    final Map.Entry entry = (Map.Entry) o;
                    Object value = entry.getValue();
                    if (value instanceof List) {
                        for (Object elem : (List) value) {
                            if (elem instanceof AtlasEdge) {
                                processEdge((AtlasEdge) elem, entities, relations);
                            } else {
                                LOG.warn("Invalid value of type {} found, ignoring", (elem != null ? elem.getClass().getSimpleName() : "null"));
                            }
                        }
                    } else if (value instanceof AtlasEdge) {
                        processEdge((AtlasEdge) value, entities, relations);
                    } else {
                        LOG.warn("Invalid value of type {} found, ignoring", (value != null ? value.getClass().getSimpleName() : "null"));
                    }
                }
            }
        }
    }
    return new AtlasLineageInfo(guid, entities, relations, direction, depth);
}
Also used : AtlasLineageInfo(org.apache.atlas.model.lineage.AtlasLineageInfo) HashMap(java.util.HashMap) LineageRelation(org.apache.atlas.model.lineage.AtlasLineageInfo.LineageRelation) AtlasEdge(org.apache.atlas.repository.graphdb.AtlasEdge) AtlasEntityHeader(org.apache.atlas.model.instance.AtlasEntityHeader) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map) HashSet(java.util.HashSet)

Example 9 with LineageRelation

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

the class EntityLineageServiceTest method testGetOutputLineageInfo.

@Test
public void testGetOutputLineageInfo() throws Exception {
    TestUtils.skipForGremlin3EnabledGraphDb();
    String entityGuid = getEntityId(HIVE_TABLE_TYPE, "name", "sales_fact");
    AtlasLineageInfo outputLineage = getOutputLineageInfo(entityGuid, 4);
    assertNotNull(outputLineage);
    System.out.println("output lineage = " + outputLineage);
    Map<String, AtlasEntityHeader> entities = outputLineage.getGuidEntityMap();
    assertNotNull(entities);
    Set<LineageRelation> relations = outputLineage.getRelations();
    assertNotNull(relations);
    Assert.assertEquals(entities.size(), 5);
    Assert.assertEquals(relations.size(), 4);
    Assert.assertEquals(outputLineage.getLineageDepth(), 4);
    Assert.assertEquals(outputLineage.getLineageDirection(), LineageDirection.OUTPUT);
    assertTrue(entities.containsKey(outputLineage.getBaseEntityGuid()));
}
Also used : AtlasLineageInfo(org.apache.atlas.model.lineage.AtlasLineageInfo) LineageRelation(org.apache.atlas.model.lineage.AtlasLineageInfo.LineageRelation) AtlasEntityHeader(org.apache.atlas.model.instance.AtlasEntityHeader) Test(org.testng.annotations.Test) BaseRepositoryTest(org.apache.atlas.BaseRepositoryTest)

Example 10 with LineageRelation

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

the class EntityLineageServiceTest method testGetInputLineageInfo.

@Test
public void testGetInputLineageInfo() throws Exception {
    TestUtils.skipForGremlin3EnabledGraphDb();
    String entityGuid = getEntityId(HIVE_TABLE_TYPE, "name", "sales_fact_monthly_mv");
    AtlasLineageInfo inputLineage = getInputLineageInfo(entityGuid, 4);
    assertNotNull(inputLineage);
    System.out.println("input lineage = " + inputLineage);
    Map<String, AtlasEntityHeader> entities = inputLineage.getGuidEntityMap();
    assertNotNull(entities);
    Set<LineageRelation> relations = inputLineage.getRelations();
    assertNotNull(relations);
    Assert.assertEquals(entities.size(), 6);
    Assert.assertEquals(relations.size(), 5);
    Assert.assertEquals(inputLineage.getLineageDepth(), 4);
    Assert.assertEquals(inputLineage.getLineageDirection(), LineageDirection.INPUT);
    assertTrue(entities.containsKey(inputLineage.getBaseEntityGuid()));
}
Also used : AtlasLineageInfo(org.apache.atlas.model.lineage.AtlasLineageInfo) LineageRelation(org.apache.atlas.model.lineage.AtlasLineageInfo.LineageRelation) AtlasEntityHeader(org.apache.atlas.model.instance.AtlasEntityHeader) Test(org.testng.annotations.Test) BaseRepositoryTest(org.apache.atlas.BaseRepositoryTest)

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