Search in sources :

Example 16 with AtlasLineageInfo

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

the class EntityLineageJerseyResourceIT method testInputLineageInfo.

@Test
public void testInputLineageInfo() throws Exception {
    String tableId = atlasClientV1.getEntity(HIVE_TABLE_TYPE, AtlasClient.REFERENCEABLE_ATTRIBUTE_NAME, salesMonthlyTable).getId()._getId();
    MultivaluedMap<String, String> queryParams = new MultivaluedMapImpl();
    queryParams.add(DIRECTION_PARAM, INPUT_DIRECTION);
    queryParams.add(DEPTH_PARAM, "5");
    JSONObject response = atlasClientV1.callAPI(LINEAGE_V2_API, JSONObject.class, queryParams, tableId);
    Assert.assertNotNull(response);
    System.out.println("input lineage info = " + response);
    AtlasLineageInfo inputLineageInfo = gson.fromJson(response.toString(), AtlasLineageInfo.class);
    Map<String, AtlasEntityHeader> entities = inputLineageInfo.getGuidEntityMap();
    Assert.assertNotNull(entities);
    Set<AtlasLineageInfo.LineageRelation> relations = inputLineageInfo.getRelations();
    Assert.assertNotNull(relations);
    Assert.assertEquals(entities.size(), 6);
    Assert.assertEquals(relations.size(), 5);
    Assert.assertEquals(inputLineageInfo.getLineageDirection(), AtlasLineageInfo.LineageDirection.INPUT);
    Assert.assertEquals(inputLineageInfo.getLineageDepth(), 5);
    Assert.assertEquals(inputLineageInfo.getBaseEntityGuid(), tableId);
}
Also used : AtlasLineageInfo(org.apache.atlas.model.lineage.AtlasLineageInfo) JSONObject(org.codehaus.jettison.json.JSONObject) AtlasEntityHeader(org.apache.atlas.model.instance.AtlasEntityHeader) MultivaluedMapImpl(com.sun.jersey.core.util.MultivaluedMapImpl) Test(org.testng.annotations.Test)

Example 17 with AtlasLineageInfo

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

the class EntityLineageJerseyResourceIT method testLineageInfo.

@Test
public void testLineageInfo() throws Exception {
    String tableId = atlasClientV1.getEntity(HIVE_TABLE_TYPE, AtlasClient.REFERENCEABLE_ATTRIBUTE_NAME, salesMonthlyTable).getId()._getId();
    MultivaluedMap<String, String> queryParams = new MultivaluedMapImpl();
    queryParams.add(DIRECTION_PARAM, BOTH_DIRECTION);
    queryParams.add(DEPTH_PARAM, "5");
    ObjectNode response = atlasClientV1.callAPI(LINEAGE_V2_API, ObjectNode.class, queryParams, tableId);
    Assert.assertNotNull(response);
    System.out.println("both lineage info = " + response);
    AtlasLineageInfo bothLineageInfo = AtlasType.fromJson(response.toString(), AtlasLineageInfo.class);
    Map<String, AtlasEntityHeader> entities = bothLineageInfo.getGuidEntityMap();
    Assert.assertNotNull(entities);
    Set<AtlasLineageInfo.LineageRelation> relations = bothLineageInfo.getRelations();
    Assert.assertNotNull(relations);
    Assert.assertEquals(entities.size(), 6);
    Assert.assertEquals(relations.size(), 5);
    Assert.assertEquals(bothLineageInfo.getLineageDirection(), AtlasLineageInfo.LineageDirection.BOTH);
    Assert.assertEquals(bothLineageInfo.getLineageDepth(), 5);
    Assert.assertEquals(bothLineageInfo.getBaseEntityGuid(), tableId);
}
Also used : AtlasLineageInfo(org.apache.atlas.model.lineage.AtlasLineageInfo) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) AtlasEntityHeader(org.apache.atlas.model.instance.AtlasEntityHeader) MultivaluedMapImpl(com.sun.jersey.core.util.MultivaluedMapImpl) Test(org.testng.annotations.Test)

Example 18 with AtlasLineageInfo

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

the class EntityLineageJerseyResourceIT method testOutputLineageInfo.

@Test
public void testOutputLineageInfo() throws Exception {
    String tableId = atlasClientV1.getEntity(HIVE_TABLE_TYPE, AtlasClient.REFERENCEABLE_ATTRIBUTE_NAME, salesFactTable).getId()._getId();
    MultivaluedMap<String, String> queryParams = new MultivaluedMapImpl();
    queryParams.add(DIRECTION_PARAM, OUTPUT_DIRECTION);
    queryParams.add(DEPTH_PARAM, "5");
    ObjectNode response = atlasClientV1.callAPI(LINEAGE_V2_API, ObjectNode.class, queryParams, tableId);
    Assert.assertNotNull(response);
    System.out.println("output lineage info = " + response);
    AtlasLineageInfo outputLineageInfo = AtlasType.fromJson(response.toString(), AtlasLineageInfo.class);
    Map<String, AtlasEntityHeader> entities = outputLineageInfo.getGuidEntityMap();
    Assert.assertNotNull(entities);
    Set<AtlasLineageInfo.LineageRelation> relations = outputLineageInfo.getRelations();
    Assert.assertNotNull(relations);
    Assert.assertEquals(entities.size(), 5);
    Assert.assertEquals(relations.size(), 4);
    Assert.assertEquals(outputLineageInfo.getLineageDirection(), AtlasLineageInfo.LineageDirection.OUTPUT);
    Assert.assertEquals(outputLineageInfo.getLineageDepth(), 5);
    Assert.assertEquals(outputLineageInfo.getBaseEntityGuid(), tableId);
}
Also used : AtlasLineageInfo(org.apache.atlas.model.lineage.AtlasLineageInfo) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) AtlasEntityHeader(org.apache.atlas.model.instance.AtlasEntityHeader) MultivaluedMapImpl(com.sun.jersey.core.util.MultivaluedMapImpl) Test(org.testng.annotations.Test)

Example 19 with AtlasLineageInfo

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

the class LineageUtils method toLineageStruct.

public static Struct toLineageStruct(AtlasLineageInfo lineageInfo, AtlasTypeRegistry registry) throws AtlasBaseException {
    Struct ret = new Struct();
    ret.setTypeName(Constants.TEMP_STRUCT_NAME_PREFIX + COUNTER.getAndIncrement());
    if (lineageInfo != null) {
        Map<String, AtlasEntityHeader> entities = lineageInfo.getGuidEntityMap();
        Set<AtlasLineageInfo.LineageRelation> relations = lineageInfo.getRelations();
        AtlasLineageInfo.LineageDirection direction = lineageInfo.getLineageDirection();
        Map<String, Struct> verticesMap = new HashMap<>();
        // Lineage Entities mapping -> verticesMap (vertices)
        for (String guid : entities.keySet()) {
            AtlasEntityHeader entityHeader = entities.get(guid);
            if (isDataSet(entityHeader.getTypeName(), registry)) {
                Map<String, Object> vertexIdMap = new HashMap<>();
                vertexIdMap.put(Constants.ATTRIBUTE_NAME_GUID, guid);
                vertexIdMap.put(Constants.ATTRIBUTE_NAME_STATE, (entityHeader.getStatus() == AtlasEntity.Status.ACTIVE) ? "ACTIVE" : "DELETED");
                vertexIdMap.put(Constants.ATTRIBUTE_NAME_TYPENAME, entityHeader.getTypeName());
                Object qualifiedName = entityHeader.getAttribute(AtlasClient.REFERENCEABLE_ATTRIBUTE_NAME);
                if (qualifiedName == null) {
                    qualifiedName = entityHeader.getDisplayText();
                }
                Map<String, Object> values = new HashMap<>();
                values.put(AtlasClient.REFERENCEABLE_ATTRIBUTE_NAME, qualifiedName);
                values.put(VERTEX_ID_ATTR_NAME, constructResultStruct(vertexIdMap, true));
                values.put(AtlasClient.NAME, entityHeader.getDisplayText());
                verticesMap.put(guid, constructResultStruct(values, false));
            }
        }
        // Lineage Relations mapping -> edgesMap (edges)
        Map<String, List<String>> edgesMap = new HashMap<>();
        for (AtlasLineageInfo.LineageRelation relation : relations) {
            String fromEntityId = relation.getFromEntityId();
            String toEntityId = relation.getToEntityId();
            if (direction == AtlasLineageInfo.LineageDirection.INPUT) {
                if (!edgesMap.containsKey(toEntityId)) {
                    edgesMap.put(toEntityId, new ArrayList<String>());
                }
                edgesMap.get(toEntityId).add(fromEntityId);
            } else if (direction == AtlasLineageInfo.LineageDirection.OUTPUT) {
                if (!edgesMap.containsKey(fromEntityId)) {
                    edgesMap.put(fromEntityId, new ArrayList<String>());
                }
                edgesMap.get(fromEntityId).add(toEntityId);
            }
        }
        ret.set("vertices", verticesMap);
        ret.set("edges", edgesMap);
    }
    return ret;
}
Also used : AtlasLineageInfo(org.apache.atlas.model.lineage.AtlasLineageInfo) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Struct(org.apache.atlas.v1.model.instance.Struct) AtlasEntityHeader(org.apache.atlas.model.instance.AtlasEntityHeader) ArrayList(java.util.ArrayList) List(java.util.List)

Example 20 with AtlasLineageInfo

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

the class HiveHookIT method testTruncateTable.

@Test
public void testTruncateTable() throws Exception {
    String tableName = createTable(false);
    String query = String.format("truncate table %s", tableName);
    runCommand(query);
    Set<WriteEntity> outputs = getOutputs(tableName, Entity.Type.TABLE);
    String tableId = assertTableIsRegistered(DEFAULT_DB, tableName);
    validateProcess(constructEvent(query, HiveOperation.TRUNCATETABLE, null, outputs));
    // Check lineage
    String datasetName = HiveMetaStoreBridge.getTableQualifiedName(CLUSTER_NAME, DEFAULT_DB, tableName);
    AtlasLineageInfo atlasLineageInfoInput = atlasClientV2.getLineageInfo(tableId, AtlasLineageInfo.LineageDirection.INPUT, 0);
    Map<String, AtlasEntityHeader> entityMap = atlasLineageInfoInput.getGuidEntityMap();
    // Below should be assertTrue - Fix https://issues.apache.org/jira/browse/ATLAS-653
    Assert.assertFalse(entityMap.containsKey(tableId));
}
Also used : AtlasLineageInfo(org.apache.atlas.model.lineage.AtlasLineageInfo) AtlasEntityHeader(org.apache.atlas.model.instance.AtlasEntityHeader) WriteEntity(org.apache.hadoop.hive.ql.hooks.WriteEntity) Test(org.testng.annotations.Test)

Aggregations

AtlasLineageInfo (org.apache.atlas.model.lineage.AtlasLineageInfo)32 AtlasEntityHeader (org.apache.atlas.model.instance.AtlasEntityHeader)24 Test (org.testng.annotations.Test)17 LineageRelation (org.apache.atlas.model.lineage.AtlasLineageInfo.LineageRelation)11 MultivaluedMapImpl (com.sun.jersey.core.util.MultivaluedMapImpl)6 Consumes (javax.ws.rs.Consumes)6 GET (javax.ws.rs.GET)6 Path (javax.ws.rs.Path)6 Produces (javax.ws.rs.Produces)6 WebApplicationException (javax.ws.rs.WebApplicationException)6 AtlasPerfTracer (org.apache.atlas.utils.AtlasPerfTracer)6 ArrayList (java.util.ArrayList)5 BaseRepositoryTest (org.apache.atlas.BaseRepositoryTest)5 AtlasBaseException (org.apache.atlas.exception.AtlasBaseException)5 JSONObject (org.codehaus.jettison.json.JSONObject)5 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)4 HashMap (java.util.HashMap)4 List (java.util.List)4 HashSet (java.util.HashSet)2 DataSetLineageResponse (org.apache.atlas.v1.model.lineage.DataSetLineageResponse)2