Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(lineage): allow lineage viz to handle circular dependencies #2413

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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