-
Notifications
You must be signed in to change notification settings - Fork 3
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
[CDF-24184] 🚍 Strongly coupled views. #1490
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
bbeb091
tests: added test case
doctrino 970243d
tests: created failing test
doctrino 4a408aa
feat: First draft tarjan
doctrino 52725fa
fix: implemented recovery
doctrino 7a6d1df
tests: added testing for tarjan
doctrino f11838a
style: fix typos
doctrino 0af3847
Merge branch 'main' into try-3-view-dependency-orders
doctrino 7efa870
Merge branch 'main' into try-3-view-dependency-orders
doctrino 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 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
This file contains 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,46 @@ | ||
from typing import TypeVar | ||
|
||
T = TypeVar("T") | ||
|
||
|
||
def tarjan(dependencies_by_id: dict[T, set[T]]) -> list[set[T]]: | ||
"""Returns the strongly connected components of the dependency graph | ||
in topological order. | ||
|
||
Args: | ||
dependencies_by_id: A dictionary where the keys are ids and the values are sets of ids that the key depends on. | ||
|
||
Returns: | ||
A list of sets of ids that are strongly connected components in the dependency graph. | ||
""" | ||
|
||
stack = [] | ||
stack_set = set() | ||
index: dict[T, int] = {} | ||
lowlink = {} | ||
result = [] | ||
|
||
def visit(v: T) -> None: | ||
index[v] = len(index) | ||
lowlink[v] = index[v] | ||
stack.append(v) | ||
stack_set.add(v) | ||
for w in dependencies_by_id.get(v, []): | ||
if w not in index: | ||
visit(w) | ||
lowlink[v] = min(lowlink[w], lowlink[v]) | ||
elif w in stack_set: | ||
lowlink[v] = min(lowlink[v], index[w]) | ||
if lowlink[v] == index[v]: | ||
scc = set() | ||
dependency: T | None = None | ||
while v != dependency: | ||
dependency = stack.pop() | ||
scc.add(dependency) | ||
stack_set.remove(dependency) | ||
result.append(scc) | ||
|
||
for view_id in dependencies_by_id.keys(): | ||
if view_id not in index: | ||
visit(view_id) | ||
return result |
This file contains 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
38 changes: 38 additions & 0 deletions
38
tests/data/strongly_coupled_model/data_models/1.Production.container.yaml
This file contains 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,38 @@ | ||
space: strongly-coupled-model | ||
externalId: Production | ||
name: Production | ||
description: Missing | ||
properties: | ||
id: | ||
type: | ||
list: false | ||
collation: ucs_basic | ||
type: text | ||
immutable: false | ||
nullable: true | ||
autoIncrement: false | ||
name: id | ||
description: Missing | ||
type: | ||
type: | ||
list: false | ||
collation: ucs_basic | ||
type: text | ||
immutable: false | ||
nullable: true | ||
autoIncrement: false | ||
name: type | ||
constraints: | ||
cogniteAssetPresent: | ||
require: | ||
space: cdf_cdm | ||
externalId: CogniteAsset | ||
type: container | ||
constraintType: requires | ||
indexes: | ||
id: | ||
properties: | ||
- id | ||
cursorable: true | ||
indexType: btree | ||
usedFor: node |
22 changes: 22 additions & 0 deletions
22
tests/data/strongly_coupled_model/data_models/10.SimNode.container.yaml
This file contains 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,22 @@ | ||
space: strongly-coupled-model | ||
externalId: SimNode | ||
name: SimNode | ||
usedFor: node | ||
description: Missing | ||
properties: | ||
coordinate: | ||
type: | ||
type: direct | ||
list: false | ||
immutable: false | ||
nullable: true | ||
autoIncrement: false | ||
name: coordinate | ||
constraints: | ||
cogniteDescribablePresent: | ||
require: | ||
space: strongly-coupled-model | ||
externalId: SimNodeAndEdge | ||
type: container | ||
constraintType: requires | ||
indexes: {} |
22 changes: 22 additions & 0 deletions
22
tests/data/strongly_coupled_model/data_models/12.SimSubNode.container.yaml
This file contains 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,22 @@ | ||
space: strongly-coupled-model | ||
externalId: SimSubNode | ||
name: SimSubNode | ||
usedFor: node | ||
description: Missing | ||
properties: | ||
parent: | ||
type: | ||
list: false | ||
type: direct | ||
immutable: false | ||
nullable: true | ||
autoIncrement: false | ||
name: parent | ||
constraints: | ||
cogniteDescribablePresent: | ||
require: | ||
space: strongly-coupled-model | ||
externalId: SimNode | ||
type: container | ||
constraintType: requires | ||
indexes: {} |
38 changes: 38 additions & 0 deletions
38
tests/data/strongly_coupled_model/data_models/13.SimEdge.container.yaml
This file contains 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,38 @@ | ||
space: strongly-coupled-model | ||
externalId: SimEdge | ||
name: SimEdge | ||
usedFor: node | ||
description: Missing | ||
properties: | ||
source: | ||
type: | ||
type: direct | ||
list: false | ||
immutable: false | ||
nullable: true | ||
autoIncrement: false | ||
name: source | ||
destination: | ||
type: | ||
type: direct | ||
list: false | ||
immutable: false | ||
nullable: true | ||
autoIncrement: false | ||
name: destination | ||
coordinates: | ||
type: | ||
type: direct | ||
list: false | ||
immutable: false | ||
nullable: true | ||
autoIncrement: false | ||
name: coordinates | ||
constraints: | ||
cogniteDescribablePresent: | ||
require: | ||
space: strongly-coupled-model | ||
externalId: SimNodeAndEdge | ||
type: container | ||
constraintType: requires | ||
indexes: {} |
67 changes: 67 additions & 0 deletions
67
tests/data/strongly_coupled_model/data_models/14.Property.container.yaml
This file contains 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,67 @@ | ||
space: strongly-coupled-model | ||
externalId: Property | ||
name: Property | ||
usedFor: node | ||
description: Missing | ||
properties: | ||
type: | ||
type: | ||
type: enum | ||
values: | ||
Input: {} | ||
Output: {} | ||
immutable: true | ||
nullable: false | ||
autoIncrement: false | ||
name: type | ||
description: Missing | ||
nodeOrEdge: | ||
type: | ||
list: false | ||
type: direct | ||
immutable: false | ||
nullable: true | ||
autoIncrement: false | ||
name: nodeOrEdge | ||
workflow: | ||
type: | ||
type: text | ||
list: false | ||
collation: ucs_basic | ||
immutable: false | ||
nullable: true | ||
autoIncrement: false | ||
name: workflow | ||
unit: | ||
type: | ||
type: text | ||
list: false | ||
collation: ucs_basic | ||
immutable: false | ||
nullable: true | ||
autoIncrement: false | ||
name: unit | ||
valueClassicRef: | ||
type: | ||
type: timeseries | ||
list: false | ||
immutable: false | ||
nullable: true | ||
autoIncrement: false | ||
name: value | ||
valueRef: | ||
type: | ||
list: false | ||
type: direct | ||
immutable: false | ||
nullable: true | ||
autoIncrement: false | ||
name: valueRef | ||
constraints: | ||
cogniteDescribablePresent: | ||
require: | ||
space: cdf_cdm | ||
externalId: CogniteDescribable | ||
type: container | ||
constraintType: requires | ||
indexes: {} |
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is handled by the new method, so we no longer need it.