-
Notifications
You must be signed in to change notification settings - Fork 403
Handle lineage graph cycles on the client #2506
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
Merged
phixMe
merged 18 commits into
MarquezProject:main
from
jlukenoff:client/lineage/handle-dependency-cycles
Jun 9, 2023
Merged
Changes from 9 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
b69d6c9
init
jlukenoff 55d1553
repro
jlukenoff 06099fa
remove log lines
jlukenoff efd8de6
formatting
jlukenoff a442c96
cleanup
jlukenoff cd62790
Create a smaller cycle
jlukenoff cf129c3
remove stub metadata
jlukenoff c5625bd
Test draft
jlukenoff 3d2156c
try stubbing some methods
jlukenoff 84e3c71
Test rendering component
jlukenoff 9506940
test without mounting
jlukenoff 0148af8
Formatting
jlukenoff abc15f8
Remove unnecessary types
jlukenoff 1d49db1
Revert new module installations
jlukenoff b2fc3af
oops
jlukenoff 08864d5
Add a test for success
jlukenoff 876bdcb
dont use ternary
jlukenoff e859de7
improve path checking
jlukenoff File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,97 @@ | ||
| // Copyright 2018-2023 contributors to the Marquez project | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| import * as React from 'react' | ||
| import { shallow } from 'enzyme' | ||
| import Lineage from '../../components/lineage/Lineage' | ||
|
|
||
| const mockGraphWithCycle = [ | ||
| { | ||
| id: 'job_foo', | ||
| type: 'JOB', | ||
| inEdges: [ | ||
| { | ||
| origin: 'dataset_foo', | ||
| destination: 'job_foo' | ||
| } | ||
| ], | ||
| outEdges: [ | ||
| { | ||
| origin: 'job_foo', | ||
| destination: 'dataset_bar' | ||
| } | ||
| ] | ||
| }, | ||
| { | ||
| id: 'dataset_bar', | ||
| type: 'DATASET', | ||
| inEdges: [ | ||
| { | ||
| origin: 'job_foo', | ||
| destination: 'dataset_bar' | ||
| } | ||
| ], | ||
| outEdges: [ | ||
| { | ||
| origin: 'dataset_bar', | ||
| destination: 'job_bar' | ||
| } | ||
| ] | ||
| }, | ||
| { | ||
| id: 'job_bar', | ||
| type: 'JOB', | ||
| inEdges: [ | ||
| { | ||
| origin: 'dataset_bar', | ||
| destination: 'job_bar' | ||
| } | ||
| ], | ||
| outEdges: [ | ||
| { | ||
| origin: 'job_bar', | ||
| destination: 'dataset_foo' | ||
| } | ||
| ] | ||
| }, | ||
| { | ||
| id: 'dataset_foo', | ||
| type: 'DATASET', | ||
| inEdges: [ | ||
| { | ||
| origin: 'job_bar', | ||
| destination: 'dataset_foo' | ||
| } | ||
| ], | ||
| outEdges: [ | ||
| { | ||
| origin: 'dataset_foo', | ||
| destination: 'job_foo' | ||
| } | ||
| ] | ||
| } | ||
| ] | ||
|
|
||
| describe('Lineage Component', () => { | ||
| const mockProps = { | ||
| setLineage: str => null | ||
| // TODO: do we really need to stub all of these? | ||
| } | ||
|
|
||
| it("doesn't follow cycles in the lineage graph", () => { | ||
| const wrapper = shallow( | ||
| <Lineage | ||
| {...mockProps} | ||
| // TODO: fix type errors, probably needs a stub interface? | ||
| lineage={mockGraphWithCycle} | ||
| selectedNode={mockGraphWithCycle[0].id} | ||
| /> | ||
| ) | ||
|
|
||
| const instance = wrapper.instance() | ||
| // TODO: fix type errors, the above stub interface will probably fix this | ||
| const paths = instance.getSelectedPaths() | ||
|
|
||
| // TODO: validate that we never have duplicate paths | ||
| }) | ||
| }) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -143,7 +143,16 @@ class Lineage extends React.Component<LineageProps, LineageState> { | |
| getSelectedPaths = () => { | ||
| const paths = [] as Array<[string, string]> | ||
|
|
||
| // Sets used to detect cycles and break out of the recursive loop | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. TBD: How would this work if we had a really large cycle with many nodes/paths involved? Perhaps we still run the risk of blowing the stack with this as well. |
||
| const visitedNodes = { | ||
| successors: new Set(), | ||
| predecessors: new Set() | ||
| } | ||
|
|
||
| const getSuccessors = (node: string) => { | ||
| if (visitedNodes.successors.has(node)) return | ||
| visitedNodes.successors.add(node) | ||
|
|
||
|
jlukenoff marked this conversation as resolved.
|
||
| const successors = g?.successors(node) | ||
| if (successors?.length) { | ||
| for (let i = 0; i < node.length - 1; i++) { | ||
|
|
@@ -156,6 +165,9 @@ class Lineage extends React.Component<LineageProps, LineageState> { | |
| } | ||
|
|
||
| const getPredecessors = (node: string) => { | ||
| if (visitedNodes.predecessors.has(node)) return | ||
| visitedNodes.predecessors.add(node) | ||
|
|
||
| const predecessors = g?.predecessors(node) | ||
| if (predecessors?.length) { | ||
| for (let i = 0; i < node.length - 1; i++) { | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.