Search in sources :

Example 1 with LineageRelation

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

the class EntityLineageService method processEdge.

private void processEdge(final AtlasEdge edge, final Map<String, AtlasEntityHeader> entities, final Set<LineageRelation> relations) throws AtlasBaseException {
    AtlasVertex inVertex = edge.getInVertex();
    AtlasVertex outVertex = edge.getOutVertex();
    String inGuid = AtlasGraphUtilsV1.getIdFromVertex(inVertex);
    String outGuid = AtlasGraphUtilsV1.getIdFromVertex(outVertex);
    String relationGuid = AtlasGraphUtilsV1.getProperty(edge, Constants.RELATIONSHIP_GUID_PROPERTY_KEY, String.class);
    boolean isInputEdge = edge.getLabel().equalsIgnoreCase(PROCESS_INPUTS_EDGE);
    if (!entities.containsKey(inGuid)) {
        AtlasEntityHeader entityHeader = entityRetriever.toAtlasEntityHeader(inVertex);
        entities.put(inGuid, entityHeader);
    }
    if (!entities.containsKey(outGuid)) {
        AtlasEntityHeader entityHeader = entityRetriever.toAtlasEntityHeader(outVertex);
        entities.put(outGuid, entityHeader);
    }
    if (isInputEdge) {
        relations.add(new LineageRelation(inGuid, outGuid, relationGuid));
    } else {
        relations.add(new LineageRelation(outGuid, inGuid, relationGuid));
    }
}
Also used : AtlasVertex(org.apache.atlas.repository.graphdb.AtlasVertex) LineageRelation(org.apache.atlas.model.lineage.AtlasLineageInfo.LineageRelation) AtlasEntityHeader(org.apache.atlas.model.instance.AtlasEntityHeader)

Example 2 with LineageRelation

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

the class QuickStartV2IT method testLineageIsMaintained.

@Test
public void testLineageIsMaintained() throws AtlasServiceException {
    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 3 with LineageRelation

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

the class EntityLineageServiceTest method testNewLineageWithDelete.

@Test
public void testNewLineageWithDelete() throws Exception {
    TestUtils.skipForGremlin3EnabledGraphDb();
    String tableName = "table" + random();
    createTable(tableName, 3, true);
    String entityGuid = getEntityId(HIVE_TABLE_TYPE, "name", tableName);
    AtlasLineageInfo inputLineage = getInputLineageInfo(entityGuid, 5);
    assertNotNull(inputLineage);
    System.out.println("input lineage = " + inputLineage);
    Map<String, AtlasEntityHeader> entitiesInput = inputLineage.getGuidEntityMap();
    assertNotNull(entitiesInput);
    assertEquals(entitiesInput.size(), 3);
    Set<LineageRelation> relationsInput = inputLineage.getRelations();
    assertNotNull(relationsInput);
    assertEquals(relationsInput.size(), 2);
    AtlasEntityHeader tableEntityInput = entitiesInput.get(entityGuid);
    assertEquals(tableEntityInput.getStatus(), Status.ACTIVE);
    AtlasLineageInfo outputLineage = getOutputLineageInfo(entityGuid, 5);
    assertNotNull(outputLineage);
    System.out.println("output lineage = " + outputLineage);
    Map<String, AtlasEntityHeader> entitiesOutput = outputLineage.getGuidEntityMap();
    assertNotNull(entitiesOutput);
    assertEquals(entitiesOutput.size(), 3);
    Set<LineageRelation> relationsOutput = outputLineage.getRelations();
    assertNotNull(relationsOutput);
    assertEquals(relationsOutput.size(), 2);
    AtlasEntityHeader tableEntityOutput = entitiesOutput.get(entityGuid);
    assertEquals(tableEntityOutput.getStatus(), Status.ACTIVE);
    AtlasLineageInfo bothLineage = getBothLineageInfo(entityGuid, 5);
    assertNotNull(bothLineage);
    System.out.println("both lineage = " + bothLineage);
    Map<String, AtlasEntityHeader> entitiesBoth = bothLineage.getGuidEntityMap();
    assertNotNull(entitiesBoth);
    assertEquals(entitiesBoth.size(), 5);
    Set<LineageRelation> relationsBoth = bothLineage.getRelations();
    assertNotNull(relationsBoth);
    assertEquals(relationsBoth.size(), 4);
    AtlasEntityHeader tableEntityBoth = entitiesBoth.get(entityGuid);
    assertEquals(tableEntityBoth.getStatus(), Status.ACTIVE);
    // Delete the table entity. Lineage for entity returns the same results as before.
    // Lineage for table name throws EntityNotFoundException
    EntityResult deleteResult = repository.deleteEntities(Arrays.asList(entityGuid));
    assertTrue(deleteResult.getDeletedEntities().contains(entityGuid));
    inputLineage = getInputLineageInfo(entityGuid, 5);
    tableEntityInput = inputLineage.getGuidEntityMap().get(entityGuid);
    assertEquals(tableEntityInput.getStatus(), Status.DELETED);
    assertEquals(inputLineage.getGuidEntityMap().size(), 3);
    outputLineage = getOutputLineageInfo(entityGuid, 5);
    tableEntityOutput = outputLineage.getGuidEntityMap().get(entityGuid);
    assertEquals(tableEntityOutput.getStatus(), Status.DELETED);
    assertEquals(outputLineage.getGuidEntityMap().size(), 3);
    bothLineage = getBothLineageInfo(entityGuid, 5);
    tableEntityBoth = bothLineage.getGuidEntityMap().get(entityGuid);
    assertEquals(tableEntityBoth.getStatus(), Status.DELETED);
    assertEquals(bothLineage.getGuidEntityMap().size(), 5);
}
Also used : AtlasLineageInfo(org.apache.atlas.model.lineage.AtlasLineageInfo) LineageRelation(org.apache.atlas.model.lineage.AtlasLineageInfo.LineageRelation) AtlasEntityHeader(org.apache.atlas.model.instance.AtlasEntityHeader) EntityResult(org.apache.atlas.model.legacy.EntityResult) Test(org.testng.annotations.Test) BaseRepositoryTest(org.apache.atlas.BaseRepositoryTest)

Example 4 with LineageRelation

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

the class EntityLineageServiceTest method testGetLineageInfo.

@Test
public void testGetLineageInfo() throws Exception {
    TestUtils.skipForGremlin3EnabledGraphDb();
    String entityGuid = getEntityId(HIVE_TABLE_TYPE, "name", "sales_fact_monthly_mv");
    AtlasLineageInfo bothLineage = getBothLineageInfo(entityGuid, 5);
    assertNotNull(bothLineage);
    System.out.println("both lineage = " + bothLineage);
    Map<String, AtlasEntityHeader> entities = bothLineage.getGuidEntityMap();
    assertNotNull(entities);
    Set<LineageRelation> relations = bothLineage.getRelations();
    assertNotNull(relations);
    Assert.assertEquals(entities.size(), 6);
    Assert.assertEquals(relations.size(), 5);
    Assert.assertEquals(bothLineage.getLineageDepth(), 5);
    Assert.assertEquals(bothLineage.getLineageDirection(), AtlasLineageInfo.LineageDirection.BOTH);
    assertTrue(entities.containsKey(bothLineage.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 5 with LineageRelation

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

the class EntityLineageServiceTest method testCircularLineage.

/**
 * Circular Lineage Test.
 */
@Test
public void testCircularLineage() throws Exception {
    TestUtils.skipForGremlin3EnabledGraphDb();
    String entityGuid = getEntityId(HIVE_TABLE_TYPE, "name", "table2");
    AtlasLineageInfo circularLineage = getInputLineageInfo(entityGuid, 5);
    assertNotNull(circularLineage);
    System.out.println("circular lineage = " + circularLineage);
    Map<String, AtlasEntityHeader> entities = circularLineage.getGuidEntityMap();
    assertNotNull(entities);
    Set<LineageRelation> relations = circularLineage.getRelations();
    assertNotNull(relations);
    Assert.assertEquals(entities.size(), 4);
    Assert.assertEquals(relations.size(), 4);
    Assert.assertEquals(circularLineage.getLineageDepth(), 5);
    Assert.assertEquals(circularLineage.getLineageDirection(), LineageDirection.INPUT);
    assertTrue(entities.containsKey(circularLineage.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