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);
}
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);
}
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);
}
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;
}
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));
}
Aggregations