mirror of
https://github.com/open-metadata/OpenMetadata.git
synced 2025-09-25 17:04:54 +00:00
parent
55e1be9ca4
commit
bb772d4140
@ -90,13 +90,19 @@ public class LineageResource {
|
||||
String entity,
|
||||
@Parameter(description = "Entity id", required = true, schema = @Schema(type = "string")) @PathParam("id")
|
||||
String id,
|
||||
@Parameter(description = "Upstream depth of lineage (default=1, min=0, max=3)") @QueryParam("upstreamDepth")
|
||||
@Parameter(description = "Upstream depth of lineage (default=1, min=0, max=3)")
|
||||
@DefaultValue("1")
|
||||
@Min(0)
|
||||
@Max(3)
|
||||
@QueryParam("upstreamDepth")
|
||||
int upstreamDepth,
|
||||
@Parameter(description = "Downstream depth of lineage (default=1, min=0, max=3)") @QueryParam("downstreamDepth")
|
||||
@Parameter(description = "Upstream depth of lineage (default=1, min=0, max=3)")
|
||||
@DefaultValue("1")
|
||||
@Min(0)
|
||||
@Max(3)
|
||||
@QueryParam("downstreamDepth")
|
||||
int downStreamDepth)
|
||||
throws IOException {
|
||||
upstreamDepth = Math.min(Math.max(upstreamDepth, 0), 3);
|
||||
downStreamDepth = Math.min(Math.max(downStreamDepth, 0), 3);
|
||||
return addHref(uriInfo, dao.get(entity, id, upstreamDepth, downStreamDepth));
|
||||
}
|
||||
|
||||
|
@ -159,24 +159,54 @@ public class LineageResourceTest extends CatalogApplicationTest {
|
||||
getEdge(TABLES.get(6), TABLES.get(7))
|
||||
};
|
||||
|
||||
// GET lineage by id
|
||||
EntityLineage lineage = getLineage(Entity.TABLE, TABLES.get(4).getId(), 3, 3, ADMIN_AUTH_HEADERS);
|
||||
assertEdges(lineage, expectedUpstreamEdges, expectedDownstreamEdges);
|
||||
|
||||
// GET lineage by fqn
|
||||
lineage = getLineageByName(Entity.TABLE, TABLES.get(4).getFullyQualifiedName(), 3, 3, ADMIN_AUTH_HEADERS);
|
||||
assertEdges(lineage, expectedUpstreamEdges, expectedDownstreamEdges);
|
||||
// GET lineage by id and fqn and ensure it is correct
|
||||
assertLineage(
|
||||
Entity.TABLE,
|
||||
TABLES.get(4).getId(),
|
||||
TABLES.get(4).getFullyQualifiedName(),
|
||||
3,
|
||||
3,
|
||||
expectedUpstreamEdges,
|
||||
expectedDownstreamEdges);
|
||||
|
||||
// Test table4 partial lineage with various upstream and downstream depths
|
||||
lineage = getLineage(Entity.TABLE, TABLES.get(4).getId(), 0, 0, ADMIN_AUTH_HEADERS);
|
||||
assertEdges(
|
||||
lineage, Arrays.copyOfRange(expectedUpstreamEdges, 0, 0), Arrays.copyOfRange(expectedDownstreamEdges, 0, 0));
|
||||
lineage = getLineage(Entity.TABLE, TABLES.get(4).getId(), 1, 1, ADMIN_AUTH_HEADERS);
|
||||
assertEdges(
|
||||
lineage, Arrays.copyOfRange(expectedUpstreamEdges, 0, 3), Arrays.copyOfRange(expectedDownstreamEdges, 0, 3));
|
||||
lineage = getLineage(Entity.TABLE, TABLES.get(4).getId(), 2, 2, ADMIN_AUTH_HEADERS);
|
||||
assertEdges(
|
||||
lineage, Arrays.copyOfRange(expectedUpstreamEdges, 0, 4), Arrays.copyOfRange(expectedDownstreamEdges, 0, 4));
|
||||
// First upstream and downstream depth of 0
|
||||
assertLineage(
|
||||
Entity.TABLE,
|
||||
TABLES.get(4).getId(),
|
||||
TABLES.get(4).getFullyQualifiedName(),
|
||||
0,
|
||||
0,
|
||||
Arrays.copyOfRange(expectedUpstreamEdges, 0, 0),
|
||||
Arrays.copyOfRange(expectedDownstreamEdges, 0, 0));
|
||||
// Upstream and downstream depth of 1
|
||||
assertLineage(
|
||||
Entity.TABLE,
|
||||
TABLES.get(4).getId(),
|
||||
TABLES.get(4).getFullyQualifiedName(),
|
||||
1,
|
||||
1,
|
||||
Arrays.copyOfRange(expectedUpstreamEdges, 0, 3),
|
||||
Arrays.copyOfRange(expectedDownstreamEdges, 0, 3));
|
||||
// Upstream and downstream depth of 2
|
||||
assertLineage(
|
||||
Entity.TABLE,
|
||||
TABLES.get(4).getId(),
|
||||
TABLES.get(4).getFullyQualifiedName(),
|
||||
2,
|
||||
2,
|
||||
Arrays.copyOfRange(expectedUpstreamEdges, 0, 4),
|
||||
Arrays.copyOfRange(expectedDownstreamEdges, 0, 4));
|
||||
|
||||
// Upstream and downstream depth as null to test for default value of 1
|
||||
assertLineage(
|
||||
Entity.TABLE,
|
||||
TABLES.get(4).getId(),
|
||||
TABLES.get(4).getFullyQualifiedName(),
|
||||
null,
|
||||
null,
|
||||
Arrays.copyOfRange(expectedUpstreamEdges, 0, 3),
|
||||
Arrays.copyOfRange(expectedDownstreamEdges, 0, 3));
|
||||
|
||||
//
|
||||
// Delete all the lineage edges
|
||||
@ -192,9 +222,10 @@ public class LineageResourceTest extends CatalogApplicationTest {
|
||||
deleteEdge(TABLES.get(4), TABLES.get(8));
|
||||
deleteEdge(TABLES.get(5), TABLES.get(6));
|
||||
deleteEdge(TABLES.get(6), TABLES.get(7));
|
||||
lineage = getLineage(Entity.TABLE, TABLES.get(4).getId(), 2, 2, ADMIN_AUTH_HEADERS);
|
||||
assertTrue(lineage.getUpstreamEdges().isEmpty());
|
||||
assertTrue(lineage.getDownstreamEdges().isEmpty());
|
||||
|
||||
// Ensure upstream and downstream lineage is empty
|
||||
assertLineage(
|
||||
Entity.TABLE, TABLES.get(4).getId(), TABLES.get(4).getFullyQualifiedName(), 2, 2, new Edge[0], new Edge[0]);
|
||||
}
|
||||
|
||||
public Edge getEdge(Table from, Table to) {
|
||||
@ -313,6 +344,25 @@ public class LineageResourceTest extends CatalogApplicationTest {
|
||||
}
|
||||
}
|
||||
|
||||
public static void assertLineage(
|
||||
String entityType,
|
||||
UUID id,
|
||||
String fqn,
|
||||
Integer upstreamDepth,
|
||||
Integer downstreamDepth,
|
||||
Edge[] expectedUpstreamEdges,
|
||||
Edge[] expectedDownstreamEdges)
|
||||
throws HttpResponseException {
|
||||
EntityLineage lineageById = getLineage(entityType, id, upstreamDepth, downstreamDepth, ADMIN_AUTH_HEADERS);
|
||||
assertEdges(lineageById, expectedUpstreamEdges, expectedDownstreamEdges);
|
||||
|
||||
EntityLineage lineageByName = getLineageByName(entityType, fqn, upstreamDepth, downstreamDepth, ADMIN_AUTH_HEADERS);
|
||||
assertEdges(lineageByName, expectedUpstreamEdges, expectedDownstreamEdges);
|
||||
|
||||
// Finally ensure lineage by Id matches lineage by name
|
||||
assertEquals(lineageById, lineageByName);
|
||||
}
|
||||
|
||||
public static EntityLineage getLineage(
|
||||
String entity, UUID id, Integer upstreamDepth, Integer downStreamDepth, Map<String, String> authHeaders)
|
||||
throws HttpResponseException {
|
||||
|
Loading…
x
Reference in New Issue
Block a user