Skip to content

Commit

Permalink
fix(lineage): allow lineage viz to handle circular dependencies (#2413)
Browse files Browse the repository at this point in the history
  • Loading branch information
gabe-lyons authored Apr 17, 2021
1 parent 1b3a145 commit 43075c4
Show file tree
Hide file tree
Showing 5 changed files with 2,145 additions and 1,882 deletions.
104 changes: 104 additions & 0 deletions datahub-web-react/src/Mocks.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,58 @@ export const dataset4WithLineage = {
},
};

export const dataset5WithCyclicalLineage = {
...dataset5,
upstreamLineage: {
upstreams: [
{
created: {
time: 0,
},
lastModified: {
time: 0,
},
type: DatasetLineageType.Transformed,
dataset: dataset3,
},
],
},
downstreamLineage: {
downstreams: [
{
created: {
time: 0,
},
lastModified: {
time: 0,
},
type: DatasetLineageType.Transformed,
dataset: dataset7,
},
{
created: {
time: 0,
},
lastModified: {
time: 0,
},
type: DatasetLineageType.Transformed,
dataset: dataset6,
},
{
created: {
time: 0,
},
lastModified: {
time: 0,
},
type: DatasetLineageType.Transformed,
dataset: dataset4,
},
],
},
};

export const dataset5WithLineage = {
...dataset5,
upstreamLineage: {
Expand Down Expand Up @@ -440,6 +492,58 @@ export const dataset7WithLineage = {
},
};

export const dataset7WithSelfReferentialLineage = {
...dataset7,
upstreamLineage: {
upstreams: [
{
created: {
time: 0,
},
lastModified: {
time: 0,
},
type: DatasetLineageType.Transformed,
dataset: dataset5,
},
{
created: {
time: 0,
},
lastModified: {
time: 0,
},
type: DatasetLineageType.Transformed,
dataset: dataset7,
},
],
},
downstreamLineage: {
downstreams: [
{
created: {
time: 0,
},
lastModified: {
time: 0,
},
type: DatasetLineageType.Transformed,
dataset: dataset3,
},
{
created: {
time: 0,
},
lastModified: {
time: 0,
},
type: DatasetLineageType.Transformed,
dataset: dataset7,
},
],
},
};

const sampleTag = {
urn: 'urn:li:tag:abc-sample-tag',
name: 'abc-sample-tag',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ import { render } from '@testing-library/react';
import {
dataset3WithLineage,
dataset4WithLineage,
dataset5WithCyclicalLineage,
dataset5WithLineage,
dataset6WithLineage,
dataset7WithLineage,
dataset7WithSelfReferentialLineage,
} from '../../../Mocks';
import constructTree from '../utils/constructTree';
import extendAsyncEntities from '../utils/extendAsyncEntities';
Expand Down Expand Up @@ -117,4 +119,131 @@ describe('adjustVXTreeLayout', () => {
</Tree>,
);
});

it('handles self referntial lineage at the root level', () => {
const fetchedEntities = [
{ entity: dataset4WithLineage, direction: Direction.Upstream, fullyFetched: true },
{ entity: dataset5WithLineage, direction: Direction.Upstream, fullyFetched: true },
{ entity: dataset6WithLineage, direction: Direction.Upstream, fullyFetched: true },
{ entity: dataset3WithLineage, direction: Direction.Upstream, fullyFetched: true },
{ entity: dataset7WithSelfReferentialLineage, direction: Direction.Upstream, fullyFetched: true },
];
const mockFetchedEntities = fetchedEntities.reduce(
(acc, entry) =>
extendAsyncEntities(
acc,
testEntityRegistry,
{ entity: entry.entity, type: EntityType.Dataset },
entry.fullyFetched,
),
{} as FetchedEntities,
);

const upstreamData = hierarchy(
constructTree(
{ entity: dataset7WithSelfReferentialLineage, type: EntityType.Dataset },
mockFetchedEntities,
Direction.Upstream,
testEntityRegistry,
),
);

render(
<Tree<NodeData> root={upstreamData} size={[1000, 1000]}>
{(tree) => {
const adjustedTree = adjustVXTreeLayout({ tree, direction: Direction.Upstream });

adjustedTree.nodesToRender.forEach((node) => {
expect(node.y).toBeLessThanOrEqual(0);
});

return <div />;
}}
</Tree>,
);
});

it('handles self referential lineage at the child level', () => {
const fetchedEntities = [
{ entity: dataset4WithLineage, direction: Direction.Upstream, fullyFetched: true },
{ entity: dataset5WithLineage, direction: Direction.Upstream, fullyFetched: true },
{ entity: dataset6WithLineage, direction: Direction.Upstream, fullyFetched: true },
{ entity: dataset7WithSelfReferentialLineage, direction: Direction.Upstream, fullyFetched: true },
];
const mockFetchedEntities = fetchedEntities.reduce(
(acc, entry) =>
extendAsyncEntities(
acc,
testEntityRegistry,
{ entity: entry.entity, type: EntityType.Dataset },
entry.fullyFetched,
),
{} as FetchedEntities,
);

const upstreamData = hierarchy(
constructTree(
{ entity: dataset3WithLineage, type: EntityType.Dataset },
mockFetchedEntities,
Direction.Upstream,
testEntityRegistry,
),
);

render(
<Tree<NodeData> root={upstreamData} size={[1000, 1000]}>
{(tree) => {
const adjustedTree = adjustVXTreeLayout({ tree, direction: Direction.Upstream });

adjustedTree.nodesToRender.forEach((node) => {
expect(node.y).toBeLessThanOrEqual(0);
});

return <div />;
}}
</Tree>,
);
});

it('handles multi-element cycle lineage', () => {
const fetchedEntities = [
{ entity: dataset4WithLineage, direction: Direction.Upstream, fullyFetched: true },
{ entity: dataset5WithCyclicalLineage, direction: Direction.Upstream, fullyFetched: true },
{ entity: dataset6WithLineage, direction: Direction.Upstream, fullyFetched: true },
{ entity: dataset7WithSelfReferentialLineage, direction: Direction.Upstream, fullyFetched: true },
];
const mockFetchedEntities = fetchedEntities.reduce(
(acc, entry) =>
extendAsyncEntities(
acc,
testEntityRegistry,
{ entity: entry.entity, type: EntityType.Dataset },
entry.fullyFetched,
),
{} as FetchedEntities,
);

const upstreamData = hierarchy(
constructTree(
{ entity: dataset3WithLineage, type: EntityType.Dataset },
mockFetchedEntities,
Direction.Upstream,
testEntityRegistry,
),
);

render(
<Tree<NodeData> root={upstreamData} size={[1000, 1000]}>
{(tree) => {
const adjustedTree = adjustVXTreeLayout({ tree, direction: Direction.Upstream });

adjustedTree.nodesToRender.forEach((node) => {
expect(node.y).toBeLessThanOrEqual(0);
});

return <div />;
}}
</Tree>,
);
});
});
Loading

0 comments on commit 43075c4

Please sign in to comment.