mirror of
https://github.com/open-metadata/OpenMetadata.git
synced 2025-09-26 17:34:41 +00:00
parent
55e1be9ca4
commit
bb772d4140
@ -90,13 +90,19 @@ public class LineageResource {
|
|||||||
String entity,
|
String entity,
|
||||||
@Parameter(description = "Entity id", required = true, schema = @Schema(type = "string")) @PathParam("id")
|
@Parameter(description = "Entity id", required = true, schema = @Schema(type = "string")) @PathParam("id")
|
||||||
String 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,
|
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)
|
int downStreamDepth)
|
||||||
throws IOException {
|
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));
|
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))
|
getEdge(TABLES.get(6), TABLES.get(7))
|
||||||
};
|
};
|
||||||
|
|
||||||
// GET lineage by id
|
// GET lineage by id and fqn and ensure it is correct
|
||||||
EntityLineage lineage = getLineage(Entity.TABLE, TABLES.get(4).getId(), 3, 3, ADMIN_AUTH_HEADERS);
|
assertLineage(
|
||||||
assertEdges(lineage, expectedUpstreamEdges, expectedDownstreamEdges);
|
Entity.TABLE,
|
||||||
|
TABLES.get(4).getId(),
|
||||||
// GET lineage by fqn
|
TABLES.get(4).getFullyQualifiedName(),
|
||||||
lineage = getLineageByName(Entity.TABLE, TABLES.get(4).getFullyQualifiedName(), 3, 3, ADMIN_AUTH_HEADERS);
|
3,
|
||||||
assertEdges(lineage, expectedUpstreamEdges, expectedDownstreamEdges);
|
3,
|
||||||
|
expectedUpstreamEdges,
|
||||||
|
expectedDownstreamEdges);
|
||||||
|
|
||||||
// Test table4 partial lineage with various upstream and downstream depths
|
// Test table4 partial lineage with various upstream and downstream depths
|
||||||
lineage = getLineage(Entity.TABLE, TABLES.get(4).getId(), 0, 0, ADMIN_AUTH_HEADERS);
|
// First upstream and downstream depth of 0
|
||||||
assertEdges(
|
assertLineage(
|
||||||
lineage, Arrays.copyOfRange(expectedUpstreamEdges, 0, 0), Arrays.copyOfRange(expectedDownstreamEdges, 0, 0));
|
Entity.TABLE,
|
||||||
lineage = getLineage(Entity.TABLE, TABLES.get(4).getId(), 1, 1, ADMIN_AUTH_HEADERS);
|
TABLES.get(4).getId(),
|
||||||
assertEdges(
|
TABLES.get(4).getFullyQualifiedName(),
|
||||||
lineage, Arrays.copyOfRange(expectedUpstreamEdges, 0, 3), Arrays.copyOfRange(expectedDownstreamEdges, 0, 3));
|
0,
|
||||||
lineage = getLineage(Entity.TABLE, TABLES.get(4).getId(), 2, 2, ADMIN_AUTH_HEADERS);
|
0,
|
||||||
assertEdges(
|
Arrays.copyOfRange(expectedUpstreamEdges, 0, 0),
|
||||||
lineage, Arrays.copyOfRange(expectedUpstreamEdges, 0, 4), Arrays.copyOfRange(expectedDownstreamEdges, 0, 4));
|
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
|
// Delete all the lineage edges
|
||||||
@ -192,9 +222,10 @@ public class LineageResourceTest extends CatalogApplicationTest {
|
|||||||
deleteEdge(TABLES.get(4), TABLES.get(8));
|
deleteEdge(TABLES.get(4), TABLES.get(8));
|
||||||
deleteEdge(TABLES.get(5), TABLES.get(6));
|
deleteEdge(TABLES.get(5), TABLES.get(6));
|
||||||
deleteEdge(TABLES.get(6), TABLES.get(7));
|
deleteEdge(TABLES.get(6), TABLES.get(7));
|
||||||
lineage = getLineage(Entity.TABLE, TABLES.get(4).getId(), 2, 2, ADMIN_AUTH_HEADERS);
|
|
||||||
assertTrue(lineage.getUpstreamEdges().isEmpty());
|
// Ensure upstream and downstream lineage is empty
|
||||||
assertTrue(lineage.getDownstreamEdges().isEmpty());
|
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) {
|
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(
|
public static EntityLineage getLineage(
|
||||||
String entity, UUID id, Integer upstreamDepth, Integer downStreamDepth, Map<String, String> authHeaders)
|
String entity, UUID id, Integer upstreamDepth, Integer downStreamDepth, Map<String, String> authHeaders)
|
||||||
throws HttpResponseException {
|
throws HttpResponseException {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user