cognite-neat 0.83.0__py3-none-any.whl → 0.84.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of cognite-neat might be problematic. Click here for more details.
- cognite/neat/_shared.py +35 -0
- cognite/neat/_version.py +1 -1
- cognite/neat/graph/loaders/_rdf2asset.py +123 -0
- cognite/neat/graph/loaders/_rdf2dms.py +2 -2
- cognite/neat/graph/stores/_base.py +7 -3
- cognite/neat/rules/exporters/_base.py +7 -2
- cognite/neat/rules/exporters/_rules2dms.py +100 -92
- cognite/neat/rules/importers/_base.py +3 -3
- cognite/neat/rules/models/_rdfpath.py +41 -2
- cognite/neat/rules/models/asset/_rules.py +5 -2
- cognite/neat/rules/models/information/_converter.py +27 -0
- cognite/neat/rules/models/information/_rules.py +6 -1
- cognite/neat/utils/cdf_loaders/_base.py +1 -9
- cognite/neat/utils/cdf_loaders/_data_modeling.py +2 -1
- cognite/neat/utils/upload.py +70 -30
- cognite/neat/workflows/steps/lib/current/rules_exporter.py +5 -5
- {cognite_neat-0.83.0.dist-info → cognite_neat-0.84.1.dist-info}/METADATA +1 -1
- {cognite_neat-0.83.0.dist-info → cognite_neat-0.84.1.dist-info}/RECORD +21 -19
- {cognite_neat-0.83.0.dist-info → cognite_neat-0.84.1.dist-info}/LICENSE +0 -0
- {cognite_neat-0.83.0.dist-info → cognite_neat-0.84.1.dist-info}/WHEEL +0 -0
- {cognite_neat-0.83.0.dist-info → cognite_neat-0.84.1.dist-info}/entry_points.txt +0 -0
cognite/neat/_shared.py
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
from abc import abstractmethod
|
|
2
|
+
from collections.abc import Hashable, Sequence
|
|
3
|
+
from dataclasses import dataclass
|
|
4
|
+
from typing import Any, TypeVar
|
|
5
|
+
|
|
6
|
+
import pandas as pd
|
|
7
|
+
|
|
8
|
+
T_ID = TypeVar("T_ID", bound=Hashable)
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
@dataclass
|
|
12
|
+
class NeatObject:
|
|
13
|
+
"""A neat object can be dumped to a dictionary."""
|
|
14
|
+
|
|
15
|
+
@abstractmethod
|
|
16
|
+
def dump(self, aggregate: bool = True) -> dict[str, Any]:
|
|
17
|
+
"""Return a dictionary representation of the object."""
|
|
18
|
+
raise NotImplementedError()
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
T_NeatObject = TypeVar("T_NeatObject", bound=NeatObject)
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
class NeatList(list, Sequence[T_NeatObject]):
|
|
25
|
+
"""A list of neat objects."""
|
|
26
|
+
|
|
27
|
+
def dump(self) -> list[dict[str, Any]]:
|
|
28
|
+
"""Return a list of dictionary representations of the objects."""
|
|
29
|
+
return [obj.dump() for obj in self]
|
|
30
|
+
|
|
31
|
+
def to_pandas(self) -> pd.DataFrame:
|
|
32
|
+
return pd.DataFrame(self.dump())
|
|
33
|
+
|
|
34
|
+
def _repr_html_(self) -> str:
|
|
35
|
+
return self.to_pandas()._repr_html_() # type: ignore[operator]
|
cognite/neat/_version.py
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
__version__ = "0.
|
|
1
|
+
__version__ = "0.84.1"
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
from collections.abc import Sequence
|
|
2
|
+
from dataclasses import dataclass, fields
|
|
3
|
+
|
|
4
|
+
from cognite.client import CogniteClient
|
|
5
|
+
from cognite.client.data_classes import AssetWrite
|
|
6
|
+
|
|
7
|
+
from cognite.neat.graph._tracking.base import Tracker
|
|
8
|
+
from cognite.neat.graph._tracking.log import LogTracker
|
|
9
|
+
from cognite.neat.graph.stores import NeatGraphStore
|
|
10
|
+
from cognite.neat.issues import NeatIssue, NeatIssueList
|
|
11
|
+
from cognite.neat.rules.models import AssetRules
|
|
12
|
+
|
|
13
|
+
from ._base import CDFLoader
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
@dataclass(frozen=True)
|
|
17
|
+
class AssetLoaderMetadataKeys:
|
|
18
|
+
"""Class holding mapping between NEAT metadata key names and their desired names
|
|
19
|
+
in CDF Asset metadata
|
|
20
|
+
|
|
21
|
+
Args:
|
|
22
|
+
start_time: Start time key name
|
|
23
|
+
end_time: End time key name
|
|
24
|
+
update_time: Update time key name
|
|
25
|
+
resurrection_time: Resurrection time key name
|
|
26
|
+
identifier: Identifier key name
|
|
27
|
+
active: Active key name
|
|
28
|
+
type: Type key name
|
|
29
|
+
"""
|
|
30
|
+
|
|
31
|
+
start_time: str = "start_time"
|
|
32
|
+
end_time: str = "end_time"
|
|
33
|
+
update_time: str = "update_time"
|
|
34
|
+
resurrection_time: str = "resurrection_time"
|
|
35
|
+
identifier: str = "identifier"
|
|
36
|
+
active: str = "active"
|
|
37
|
+
type: str = "type"
|
|
38
|
+
|
|
39
|
+
def as_aliases(self) -> dict[str, str]:
|
|
40
|
+
return {str(field.default): getattr(self, field.name) for field in fields(self)}
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
class AssetLoader(CDFLoader[AssetWrite]):
|
|
44
|
+
def __init__(
|
|
45
|
+
self,
|
|
46
|
+
rules: AssetRules,
|
|
47
|
+
graph_store: NeatGraphStore,
|
|
48
|
+
data_set_id: int,
|
|
49
|
+
use_orphanage: bool = False,
|
|
50
|
+
use_labels: bool = False,
|
|
51
|
+
asset_external_id_prefix: str | None = None,
|
|
52
|
+
metadata_keys: AssetLoaderMetadataKeys | None = None,
|
|
53
|
+
create_issues: Sequence[NeatIssue] | None = None,
|
|
54
|
+
tracker: type[Tracker] | None = None,
|
|
55
|
+
):
|
|
56
|
+
super().__init__(graph_store)
|
|
57
|
+
|
|
58
|
+
self.rules = rules
|
|
59
|
+
self.data_set_id = data_set_id
|
|
60
|
+
self.use_labels = use_labels
|
|
61
|
+
self.use_orphanage = use_orphanage
|
|
62
|
+
|
|
63
|
+
self.orphanage_external_id = (
|
|
64
|
+
f"{asset_external_id_prefix or ''}orphanage-{data_set_id}" if use_orphanage else None
|
|
65
|
+
)
|
|
66
|
+
|
|
67
|
+
self.asset_external_id_prefix = asset_external_id_prefix
|
|
68
|
+
self.metadata_keys = metadata_keys or AssetLoaderMetadataKeys()
|
|
69
|
+
|
|
70
|
+
self._issues = NeatIssueList[NeatIssue](create_issues or [])
|
|
71
|
+
self._tracker: type[Tracker] = tracker or LogTracker
|
|
72
|
+
|
|
73
|
+
@classmethod
|
|
74
|
+
def from_rules(
|
|
75
|
+
cls,
|
|
76
|
+
rules: AssetRules,
|
|
77
|
+
graph_store: NeatGraphStore,
|
|
78
|
+
data_set_id: int,
|
|
79
|
+
use_orphanage: bool = False,
|
|
80
|
+
use_labels: bool = False,
|
|
81
|
+
asset_external_id_prefix: str | None = None,
|
|
82
|
+
metadata_keys: AssetLoaderMetadataKeys | None = None,
|
|
83
|
+
) -> "AssetLoader":
|
|
84
|
+
issues: list[NeatIssue] = []
|
|
85
|
+
|
|
86
|
+
return cls(
|
|
87
|
+
rules, graph_store, data_set_id, use_orphanage, use_labels, asset_external_id_prefix, metadata_keys, issues
|
|
88
|
+
)
|
|
89
|
+
|
|
90
|
+
def _create_validation_classes(self) -> None:
|
|
91
|
+
# need to get back class-property pairs where are definition of
|
|
92
|
+
# asset implementations, extend InformationRulesAnalysis make it generic
|
|
93
|
+
|
|
94
|
+
# by default if there is not explicitly stated external_id
|
|
95
|
+
# use rdf:type and drop the prefix
|
|
96
|
+
|
|
97
|
+
# based on those create pydantic model AssetDefinition
|
|
98
|
+
# which will have .to_asset_write()
|
|
99
|
+
|
|
100
|
+
raise NotImplementedError("Not implemented yet, this is placeholder")
|
|
101
|
+
|
|
102
|
+
def categorize_assets(self, client: CogniteClient) -> None:
|
|
103
|
+
"""Categorize assets to those to be created, updated, decommissioned, or resurrected"""
|
|
104
|
+
|
|
105
|
+
raise NotImplementedError("Not implemented yet, this is placeholder")
|
|
106
|
+
|
|
107
|
+
def load_to_cdf(self, client: CogniteClient, dry_run: bool = False) -> Sequence[AssetWrite]:
|
|
108
|
+
# generate assets
|
|
109
|
+
# check for circular asset hierarchy
|
|
110
|
+
# check for orphaned assets
|
|
111
|
+
# batch upsert of assets to CDF (otherwise we will hit the API rate limit)
|
|
112
|
+
|
|
113
|
+
raise NotImplementedError("Not implemented yet, this is placeholder")
|
|
114
|
+
|
|
115
|
+
@classmethod
|
|
116
|
+
def _check_for_circular_asset_hierarchy(cls, assets: list[AssetWrite]) -> None:
|
|
117
|
+
"""Check for circular references in the asset rules"""
|
|
118
|
+
raise NotImplementedError("Not implemented yet, this is placeholder")
|
|
119
|
+
|
|
120
|
+
@classmethod
|
|
121
|
+
def _check_for_orphaned_assets(cls, assets: list[AssetWrite]) -> None:
|
|
122
|
+
"""Check for circular references in the asset rules"""
|
|
123
|
+
raise NotImplementedError("Not implemented yet, this is placeholder")
|
|
@@ -34,14 +34,14 @@ class DMSLoader(CDFLoader[dm.InstanceApply]):
|
|
|
34
34
|
data_model: dm.DataModel[dm.View] | None,
|
|
35
35
|
instance_space: str,
|
|
36
36
|
class_by_view_id: dict[ViewId, str] | None = None,
|
|
37
|
-
|
|
37
|
+
create_issues: Sequence[NeatIssue] | None = None,
|
|
38
38
|
tracker: type[Tracker] | None = None,
|
|
39
39
|
):
|
|
40
40
|
super().__init__(graph_store)
|
|
41
41
|
self.data_model = data_model
|
|
42
42
|
self.instance_space = instance_space
|
|
43
43
|
self.class_by_view_id = class_by_view_id or {}
|
|
44
|
-
self._issues = NeatIssueList[NeatIssue](
|
|
44
|
+
self._issues = NeatIssueList[NeatIssue](create_issues or [])
|
|
45
45
|
self._tracker: type[Tracker] = tracker or LogTracker
|
|
46
46
|
|
|
47
47
|
@classmethod
|
|
@@ -14,8 +14,8 @@ from cognite.neat.graph.extractors import RdfFileExtractor, TripleExtractors
|
|
|
14
14
|
from cognite.neat.graph.models import Triple
|
|
15
15
|
from cognite.neat.graph.queries import Queries
|
|
16
16
|
from cognite.neat.graph.transformers import Transformers
|
|
17
|
+
from cognite.neat.rules.models import InformationRules
|
|
17
18
|
from cognite.neat.rules.models.entities import ClassEntity
|
|
18
|
-
from cognite.neat.rules.models.information import InformationRules
|
|
19
19
|
from cognite.neat.utils.auxiliary import local_import
|
|
20
20
|
|
|
21
21
|
from ._provenance import Change, Provenance
|
|
@@ -66,7 +66,8 @@ class NeatGraphStore:
|
|
|
66
66
|
|
|
67
67
|
def add_rules(self, rules: InformationRules) -> None:
|
|
68
68
|
"""This method is used to add rules to the graph store and it is the only correct
|
|
69
|
-
way to add rules to the graph store, after the graph store has been initialized.
|
|
69
|
+
way to add rules to the graph store, after the graph store has been initialized.
|
|
70
|
+
"""
|
|
70
71
|
|
|
71
72
|
self.rules = rules
|
|
72
73
|
self.base_namespace = self.rules.metadata.namespace
|
|
@@ -169,7 +170,10 @@ class NeatGraphStore:
|
|
|
169
170
|
# not yet developed
|
|
170
171
|
|
|
171
172
|
if not self.rules:
|
|
172
|
-
warnings.warn(
|
|
173
|
+
warnings.warn(
|
|
174
|
+
"No rules found for the graph store, returning empty list.",
|
|
175
|
+
stacklevel=2,
|
|
176
|
+
)
|
|
173
177
|
return []
|
|
174
178
|
|
|
175
179
|
class_entity = ClassEntity(prefix=self.rules.metadata.prefix, suffix=class_)
|
|
@@ -7,7 +7,7 @@ from cognite.client import CogniteClient
|
|
|
7
7
|
|
|
8
8
|
from cognite.neat.rules._shared import Rules
|
|
9
9
|
from cognite.neat.rules.models import DMSRules, InformationRules, RoleTypes
|
|
10
|
-
from cognite.neat.utils.upload import
|
|
10
|
+
from cognite.neat.utils.upload import UploadResult, UploadResultList
|
|
11
11
|
|
|
12
12
|
T_Export = TypeVar("T_Export")
|
|
13
13
|
|
|
@@ -37,5 +37,10 @@ class BaseExporter(ABC, Generic[T_Export]):
|
|
|
37
37
|
|
|
38
38
|
class CDFExporter(BaseExporter[T_Export]):
|
|
39
39
|
@abstractmethod
|
|
40
|
-
def
|
|
40
|
+
def export_to_cdf_iterable(
|
|
41
|
+
self, rules: Rules, client: CogniteClient, dry_run: bool = False
|
|
42
|
+
) -> Iterable[UploadResult]:
|
|
41
43
|
raise NotImplementedError
|
|
44
|
+
|
|
45
|
+
def export_to_cdf(self, rules: Rules, client: CogniteClient, dry_run: bool = False) -> UploadResultList:
|
|
46
|
+
return UploadResultList(self.export_to_cdf_iterable(rules, client, dry_run))
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import warnings
|
|
2
|
-
from collections.abc import Collection, Iterable
|
|
2
|
+
from collections.abc import Collection, Hashable, Iterable, Sequence
|
|
3
3
|
from pathlib import Path
|
|
4
4
|
from typing import Literal, TypeAlias, cast
|
|
5
5
|
|
|
@@ -31,7 +31,7 @@ from cognite.neat.utils.cdf_loaders import (
|
|
|
31
31
|
TransformationLoader,
|
|
32
32
|
ViewLoader,
|
|
33
33
|
)
|
|
34
|
-
from cognite.neat.utils.upload import
|
|
34
|
+
from cognite.neat.utils.upload import UploadResult
|
|
35
35
|
|
|
36
36
|
from ._base import CDFExporter
|
|
37
37
|
|
|
@@ -123,109 +123,84 @@ class DMSExporter(CDFExporter[DMSSchema]):
|
|
|
123
123
|
raise ValueError(f"{type(rules).__name__} cannot be exported to DMS")
|
|
124
124
|
return dms_rules.as_schema(include_pipeline=self.export_pipeline, instance_space=self.instance_space)
|
|
125
125
|
|
|
126
|
-
def delete_from_cdf(self, rules: Rules, client: CogniteClient, dry_run: bool = False) -> Iterable[
|
|
127
|
-
|
|
126
|
+
def delete_from_cdf(self, rules: Rules, client: CogniteClient, dry_run: bool = False) -> Iterable[UploadResult]:
|
|
127
|
+
to_export = self._prepare_exporters(rules, client)
|
|
128
128
|
|
|
129
129
|
# we need to reverse order in which we are picking up the items to delete
|
|
130
130
|
# as they are sorted in the order of creation and we need to delete them in reverse order
|
|
131
|
-
for
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
to_delete = []
|
|
138
|
-
|
|
139
|
-
for item in items:
|
|
131
|
+
for items, loader in reversed(to_export):
|
|
132
|
+
item_ids = loader.get_ids(items)
|
|
133
|
+
existing_items = loader.retrieve(item_ids)
|
|
134
|
+
existing_ids = loader.get_ids(existing_items)
|
|
135
|
+
to_delete: list[Hashable] = []
|
|
136
|
+
for item_id in item_ids:
|
|
140
137
|
if (
|
|
141
138
|
isinstance(loader, DataModelingLoader)
|
|
142
139
|
and self.include_space is not None
|
|
143
|
-
and not loader.in_space(
|
|
140
|
+
and not loader.in_space(item_id, self.include_space)
|
|
144
141
|
):
|
|
145
142
|
continue
|
|
146
143
|
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
to_delete.append(cdf_item)
|
|
150
|
-
|
|
151
|
-
deleted = len(to_delete)
|
|
152
|
-
failed_deleted = 0
|
|
144
|
+
if item_id in existing_ids:
|
|
145
|
+
to_delete.append(item_id)
|
|
153
146
|
|
|
147
|
+
deleted: set[Hashable] = set()
|
|
148
|
+
failed_deleted: set[Hashable] = set()
|
|
154
149
|
error_messages: list[str] = []
|
|
155
|
-
if
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
150
|
+
if dry_run:
|
|
151
|
+
deleted.update(to_delete)
|
|
152
|
+
elif to_delete:
|
|
153
|
+
try:
|
|
154
|
+
loader.delete(to_delete)
|
|
155
|
+
except CogniteAPIError as e:
|
|
156
|
+
failed_deleted.update(loader.get_id(item) for item in e.failed + e.unknown)
|
|
157
|
+
deleted.update(loader.get_id(item) for item in e.successful)
|
|
158
|
+
error_messages.append(f"Failed delete: {e.message}")
|
|
159
|
+
else:
|
|
160
|
+
deleted.update(to_delete)
|
|
163
161
|
|
|
164
|
-
yield
|
|
162
|
+
yield UploadResult(
|
|
165
163
|
name=loader.resource_name,
|
|
166
164
|
deleted=deleted,
|
|
167
|
-
skipped=0,
|
|
168
165
|
failed_deleted=failed_deleted,
|
|
169
166
|
error_messages=error_messages,
|
|
170
167
|
)
|
|
171
168
|
|
|
172
|
-
def
|
|
173
|
-
|
|
169
|
+
def export_to_cdf_iterable(
|
|
170
|
+
self, rules: Rules, client: CogniteClient, dry_run: bool = False
|
|
171
|
+
) -> Iterable[UploadResult]:
|
|
172
|
+
to_export = self._prepare_exporters(rules, client)
|
|
174
173
|
|
|
175
|
-
# The conversion from DMS to GraphQL does not seem to be triggered even if the views
|
|
176
|
-
# are changed. This is a workaround to force the conversion.
|
|
177
174
|
redeploy_data_model = False
|
|
175
|
+
for items, loader in to_export:
|
|
176
|
+
# The conversion from DMS to GraphQL does not seem to be triggered even if the views
|
|
177
|
+
# are changed. This is a workaround to force the conversion.
|
|
178
|
+
is_redeploying = loader is DataModelingLoader and redeploy_data_model
|
|
178
179
|
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
item_ids = [item_id for item_id in all_item_ids]
|
|
183
|
-
cdf_items = loader.retrieve(item_ids)
|
|
184
|
-
cdf_item_by_id = {loader.get_id(item): item for item in cdf_items}
|
|
185
|
-
items = [item for item in all_items if loader.get_id(item) in item_ids]
|
|
186
|
-
to_create, to_update, unchanged, to_delete = [], [], [], []
|
|
187
|
-
is_redeploying = loader.resource_name == "data_models" and redeploy_data_model
|
|
188
|
-
for item in items:
|
|
189
|
-
if (
|
|
190
|
-
isinstance(loader, DataModelingLoader)
|
|
191
|
-
and self.include_space is not None
|
|
192
|
-
and not loader.in_space(item, self.include_space)
|
|
193
|
-
):
|
|
194
|
-
continue
|
|
195
|
-
|
|
196
|
-
cdf_item = cdf_item_by_id.get(loader.get_id(item))
|
|
197
|
-
if cdf_item is None:
|
|
198
|
-
to_create.append(item)
|
|
199
|
-
elif is_redeploying:
|
|
200
|
-
to_update.append(item)
|
|
201
|
-
to_delete.append(cdf_item)
|
|
202
|
-
elif loader.are_equal(item, cdf_item):
|
|
203
|
-
unchanged.append(item)
|
|
204
|
-
else:
|
|
205
|
-
to_update.append(item)
|
|
206
|
-
|
|
207
|
-
created = len(to_create)
|
|
208
|
-
failed_created = 0
|
|
209
|
-
skipped = 0
|
|
210
|
-
|
|
211
|
-
if self.existing_handling in ["update", "force"]:
|
|
212
|
-
changed = len(to_update)
|
|
213
|
-
failed_changed = 0
|
|
214
|
-
elif self.existing_handling == "skip":
|
|
215
|
-
changed = 0
|
|
216
|
-
failed_changed = 0
|
|
217
|
-
skipped += len(to_update)
|
|
218
|
-
elif self.existing_handling == "fail":
|
|
219
|
-
failed_changed = len(to_update)
|
|
220
|
-
changed = 0
|
|
221
|
-
else:
|
|
222
|
-
raise ValueError(f"Unsupported existing_handling {self.existing_handling}")
|
|
180
|
+
to_create, to_delete, to_update, unchanged = self._categorize_items_for_upload(
|
|
181
|
+
loader, items, is_redeploying
|
|
182
|
+
)
|
|
223
183
|
|
|
184
|
+
issue_list = IssueList()
|
|
224
185
|
warning_list = self._validate(loader, items)
|
|
225
186
|
issue_list.extend(warning_list)
|
|
226
187
|
|
|
188
|
+
created: set[Hashable] = set()
|
|
189
|
+
skipped: set[Hashable] = set()
|
|
190
|
+
changed: set[Hashable] = set()
|
|
191
|
+
failed_created: set[Hashable] = set()
|
|
192
|
+
failed_changed: set[Hashable] = set()
|
|
227
193
|
error_messages: list[str] = []
|
|
228
|
-
if
|
|
194
|
+
if dry_run:
|
|
195
|
+
if self.existing_handling in ["update", "force"]:
|
|
196
|
+
changed.update(loader.get_id(item) for item in to_update)
|
|
197
|
+
elif self.existing_handling == "skip":
|
|
198
|
+
skipped.update(loader.get_id(item) for item in to_update)
|
|
199
|
+
elif self.existing_handling == "fail":
|
|
200
|
+
failed_changed.update(loader.get_id(item) for item in to_update)
|
|
201
|
+
else:
|
|
202
|
+
raise ValueError(f"Unsupported existing_handling {self.existing_handling}")
|
|
203
|
+
else:
|
|
229
204
|
if to_delete:
|
|
230
205
|
try:
|
|
231
206
|
loader.delete(to_delete)
|
|
@@ -238,23 +213,31 @@ class DMSExporter(CDFExporter[DMSSchema]):
|
|
|
238
213
|
try:
|
|
239
214
|
loader.create(to_create)
|
|
240
215
|
except CogniteAPIError as e:
|
|
241
|
-
failed_created
|
|
242
|
-
created
|
|
216
|
+
failed_created.update(loader.get_id(item) for item in e.failed + e.unknown)
|
|
217
|
+
created.update(loader.get_id(item) for item in e.successful)
|
|
243
218
|
error_messages.append(e.message)
|
|
219
|
+
else:
|
|
220
|
+
created.update(loader.get_id(item) for item in to_create)
|
|
244
221
|
|
|
245
222
|
if self.existing_handling in ["update", "force"]:
|
|
246
223
|
try:
|
|
247
224
|
loader.update(to_update)
|
|
248
225
|
except CogniteAPIError as e:
|
|
249
|
-
failed_changed
|
|
250
|
-
changed
|
|
226
|
+
failed_changed.update(loader.get_id(item) for item in e.failed + e.unknown)
|
|
227
|
+
changed.update(loader.get_id(item) for item in e.successful)
|
|
251
228
|
error_messages.append(e.message)
|
|
252
|
-
|
|
253
|
-
|
|
229
|
+
else:
|
|
230
|
+
changed.update(loader.get_id(item) for item in to_update)
|
|
231
|
+
elif self.existing_handling == "skip":
|
|
232
|
+
skipped.update(loader.get_id(item) for item in to_update)
|
|
233
|
+
elif self.existing_handling == "fail":
|
|
234
|
+
failed_changed.update(loader.get_id(item) for item in to_update)
|
|
235
|
+
|
|
236
|
+
yield UploadResult(
|
|
254
237
|
name=loader.resource_name,
|
|
255
238
|
created=created,
|
|
256
239
|
changed=changed,
|
|
257
|
-
unchanged=
|
|
240
|
+
unchanged={loader.get_id(item) for item in unchanged},
|
|
258
241
|
skipped=skipped,
|
|
259
242
|
failed_created=failed_created,
|
|
260
243
|
failed_changed=failed_changed,
|
|
@@ -262,12 +245,37 @@ class DMSExporter(CDFExporter[DMSSchema]):
|
|
|
262
245
|
issues=issue_list,
|
|
263
246
|
)
|
|
264
247
|
|
|
265
|
-
if loader
|
|
248
|
+
if loader is ViewLoader and (created or changed):
|
|
266
249
|
redeploy_data_model = True
|
|
267
250
|
|
|
268
|
-
def
|
|
269
|
-
self,
|
|
270
|
-
) -> tuple[
|
|
251
|
+
def _categorize_items_for_upload(
|
|
252
|
+
self, loader: ResourceLoader, items: Sequence[CogniteResource], is_redeploying
|
|
253
|
+
) -> tuple[list[CogniteResource], list[CogniteResource], list[CogniteResource], list[CogniteResource]]:
|
|
254
|
+
item_ids = loader.get_ids(items)
|
|
255
|
+
cdf_items = loader.retrieve(item_ids)
|
|
256
|
+
cdf_item_by_id = {loader.get_id(item): item for item in cdf_items}
|
|
257
|
+
to_create, to_update, unchanged, to_delete = [], [], [], []
|
|
258
|
+
for item in items:
|
|
259
|
+
if (
|
|
260
|
+
isinstance(loader, DataModelingLoader)
|
|
261
|
+
and self.include_space is not None
|
|
262
|
+
and not loader.in_space(item, self.include_space)
|
|
263
|
+
):
|
|
264
|
+
continue
|
|
265
|
+
|
|
266
|
+
cdf_item = cdf_item_by_id.get(loader.get_id(item))
|
|
267
|
+
if cdf_item is None:
|
|
268
|
+
to_create.append(item)
|
|
269
|
+
elif is_redeploying:
|
|
270
|
+
to_update.append(item)
|
|
271
|
+
to_delete.append(cdf_item)
|
|
272
|
+
elif loader.are_equal(item, cdf_item):
|
|
273
|
+
unchanged.append(item)
|
|
274
|
+
else:
|
|
275
|
+
to_update.append(item)
|
|
276
|
+
return to_create, to_delete, to_update, unchanged
|
|
277
|
+
|
|
278
|
+
def _prepare_exporters(self, rules, client) -> list[tuple[CogniteResourceList, ResourceLoader]]:
|
|
271
279
|
schema = self.export(rules)
|
|
272
280
|
to_export: list[tuple[CogniteResourceList, ResourceLoader]] = []
|
|
273
281
|
if self.export_components.intersection({"all", "spaces"}):
|
|
@@ -282,9 +290,9 @@ class DMSExporter(CDFExporter[DMSSchema]):
|
|
|
282
290
|
to_export.append((schema.databases, RawDatabaseLoader(client)))
|
|
283
291
|
to_export.append((schema.raw_tables, RawTableLoader(client)))
|
|
284
292
|
to_export.append((schema.transformations, TransformationLoader(client)))
|
|
285
|
-
return
|
|
293
|
+
return to_export
|
|
286
294
|
|
|
287
|
-
def _validate(self, loader: ResourceLoader, items:
|
|
295
|
+
def _validate(self, loader: ResourceLoader, items: CogniteResourceList) -> IssueList:
|
|
288
296
|
issue_list = IssueList()
|
|
289
297
|
if isinstance(loader, DataModelLoader):
|
|
290
298
|
models = cast(list[DataModelApply], items)
|
|
@@ -11,7 +11,7 @@ from rdflib import Namespace
|
|
|
11
11
|
|
|
12
12
|
from cognite.neat.rules._shared import Rules
|
|
13
13
|
from cognite.neat.rules.issues.base import IssueList, NeatValidationError, ValidationWarning
|
|
14
|
-
from cognite.neat.rules.models import DMSRules, InformationRules, RoleTypes
|
|
14
|
+
from cognite.neat.rules.models import AssetRules, DMSRules, InformationRules, RoleTypes
|
|
15
15
|
|
|
16
16
|
|
|
17
17
|
class BaseImporter(ABC):
|
|
@@ -48,9 +48,9 @@ class BaseImporter(ABC):
|
|
|
48
48
|
|
|
49
49
|
if rules.metadata.role is role or role is None:
|
|
50
50
|
output = rules
|
|
51
|
-
elif isinstance(rules, DMSRules) and role is RoleTypes.information_architect:
|
|
51
|
+
elif isinstance(rules, DMSRules) or isinstance(rules, AssetRules) and role is RoleTypes.information_architect:
|
|
52
52
|
output = rules.as_information_architect_rules()
|
|
53
|
-
elif isinstance(rules, InformationRules) and role is RoleTypes.dms_architect:
|
|
53
|
+
elif isinstance(rules, InformationRules) or isinstance(rules, AssetRules) and role is RoleTypes.dms_architect:
|
|
54
54
|
output = rules.as_dms_architect_rules()
|
|
55
55
|
else:
|
|
56
56
|
raise NotImplementedError(f"Role {role} is not supported for {type(rules).__name__} rules")
|
|
@@ -6,7 +6,7 @@ from collections import Counter
|
|
|
6
6
|
from functools import total_ordering
|
|
7
7
|
from typing import ClassVar, Literal
|
|
8
8
|
|
|
9
|
-
from pydantic import BaseModel, field_validator
|
|
9
|
+
from pydantic import BaseModel, field_validator, model_serializer
|
|
10
10
|
|
|
11
11
|
from cognite.neat.rules import exceptions
|
|
12
12
|
|
|
@@ -82,6 +82,7 @@ TABLE_REGEX_COMPILED = re.compile(
|
|
|
82
82
|
|
|
83
83
|
StepDirection = Literal["source", "target", "origin"]
|
|
84
84
|
_direction_by_symbol: dict[str, StepDirection] = {"->": "target", "<-": "source"}
|
|
85
|
+
_symbol_by_direction: dict[StepDirection, str] = {"source": "<-", "target": "->"}
|
|
85
86
|
|
|
86
87
|
Undefined = type(object())
|
|
87
88
|
Unknown = type(object())
|
|
@@ -196,10 +197,29 @@ class Step(BaseModel):
|
|
|
196
197
|
msg += " ->prefix:suffix, <-prefix:suffix, ->prefix:suffix(prefix:suffix) or <-prefix:suffix(prefix:suffix)"
|
|
197
198
|
raise ValueError(msg)
|
|
198
199
|
|
|
200
|
+
def __str__(self) -> str:
|
|
201
|
+
if self.property:
|
|
202
|
+
return f"{self.class_}({self.property})"
|
|
203
|
+
else:
|
|
204
|
+
return f"{_symbol_by_direction[self.direction]}{self.class_}"
|
|
205
|
+
|
|
206
|
+
def __repr__(self) -> str:
|
|
207
|
+
return self.__str__()
|
|
208
|
+
|
|
199
209
|
|
|
200
210
|
class Traversal(BaseModel):
|
|
201
211
|
class_: Entity
|
|
202
212
|
|
|
213
|
+
def __str__(self) -> str:
|
|
214
|
+
return f"{self.class_}"
|
|
215
|
+
|
|
216
|
+
def __repr__(self) -> str:
|
|
217
|
+
return self.__str__()
|
|
218
|
+
|
|
219
|
+
@model_serializer(when_used="unless-none", return_type=str)
|
|
220
|
+
def as_str(self) -> str:
|
|
221
|
+
return str(self)
|
|
222
|
+
|
|
203
223
|
|
|
204
224
|
class SingleProperty(Traversal):
|
|
205
225
|
property: Entity
|
|
@@ -208,6 +228,9 @@ class SingleProperty(Traversal):
|
|
|
208
228
|
def from_string(cls, class_: str, property_: str) -> Self:
|
|
209
229
|
return cls(class_=Entity.from_string(class_), property=Entity.from_string(property_))
|
|
210
230
|
|
|
231
|
+
def __str__(self) -> str:
|
|
232
|
+
return f"{self.class_}({self.property})"
|
|
233
|
+
|
|
211
234
|
|
|
212
235
|
class AllReferences(Traversal):
|
|
213
236
|
@classmethod
|
|
@@ -220,6 +243,9 @@ class AllProperties(Traversal):
|
|
|
220
243
|
def from_string(cls, class_: str) -> Self:
|
|
221
244
|
return cls(class_=Entity.from_string(class_))
|
|
222
245
|
|
|
246
|
+
def __str__(self) -> str:
|
|
247
|
+
return f"{self.class_}(*)"
|
|
248
|
+
|
|
223
249
|
|
|
224
250
|
class Origin(BaseModel):
|
|
225
251
|
class_: Entity
|
|
@@ -245,6 +271,9 @@ class Hop(Traversal):
|
|
|
245
271
|
),
|
|
246
272
|
)
|
|
247
273
|
|
|
274
|
+
def __str__(self) -> str:
|
|
275
|
+
return f"{self.class_}{''.join([str(step) for step in self.traversal])}"
|
|
276
|
+
|
|
248
277
|
|
|
249
278
|
class TableLookup(BaseModel):
|
|
250
279
|
name: str
|
|
@@ -261,7 +290,17 @@ class Query(BaseModel):
|
|
|
261
290
|
|
|
262
291
|
|
|
263
292
|
class RDFPath(Rule):
|
|
264
|
-
traversal:
|
|
293
|
+
traversal: SingleProperty | AllProperties | AllReferences | Hop
|
|
294
|
+
|
|
295
|
+
def __str__(self) -> str:
|
|
296
|
+
return f"{self.traversal}"
|
|
297
|
+
|
|
298
|
+
def __repr__(self) -> str:
|
|
299
|
+
return self.__str__()
|
|
300
|
+
|
|
301
|
+
@model_serializer(when_used="unless-none", return_type=str)
|
|
302
|
+
def as_str(self) -> str:
|
|
303
|
+
return str(self)
|
|
265
304
|
|
|
266
305
|
|
|
267
306
|
class RawLookup(RDFPath):
|
|
@@ -148,9 +148,12 @@ class AssetRules(BaseRules):
|
|
|
148
148
|
def as_domain_rules(self) -> DomainRules:
|
|
149
149
|
from ._converter import _AssetRulesConverter
|
|
150
150
|
|
|
151
|
-
return _AssetRulesConverter(
|
|
151
|
+
return _AssetRulesConverter(self.as_information_architect_rules()).as_domain_rules()
|
|
152
152
|
|
|
153
153
|
def as_dms_architect_rules(self) -> "DMSRules":
|
|
154
154
|
from ._converter import _AssetRulesConverter
|
|
155
155
|
|
|
156
|
-
return _AssetRulesConverter(
|
|
156
|
+
return _AssetRulesConverter(self.as_information_architect_rules()).as_dms_architect_rules()
|
|
157
|
+
|
|
158
|
+
def as_information_architect_rules(self) -> InformationRules:
|
|
159
|
+
return InformationRules.model_validate(self.model_dump())
|
|
@@ -16,11 +16,15 @@ from cognite.neat.rules.models._constants import DMS_CONTAINER_SIZE_LIMIT
|
|
|
16
16
|
from cognite.neat.rules.models.data_types import DataType
|
|
17
17
|
from cognite.neat.rules.models.domain import DomainRules
|
|
18
18
|
from cognite.neat.rules.models.entities import (
|
|
19
|
+
AssetEntity,
|
|
20
|
+
AssetFields,
|
|
19
21
|
ClassEntity,
|
|
20
22
|
ContainerEntity,
|
|
21
23
|
DMSUnknownEntity,
|
|
24
|
+
EntityTypes,
|
|
22
25
|
MultiValueTypeInfo,
|
|
23
26
|
ReferenceEntity,
|
|
27
|
+
RelationshipEntity,
|
|
24
28
|
UnknownEntity,
|
|
25
29
|
ViewEntity,
|
|
26
30
|
ViewPropertyEntity,
|
|
@@ -29,6 +33,7 @@ from cognite.neat.rules.models.entities import (
|
|
|
29
33
|
from ._rules import InformationClass, InformationMetadata, InformationProperty, InformationRules
|
|
30
34
|
|
|
31
35
|
if TYPE_CHECKING:
|
|
36
|
+
from cognite.neat.rules.models.asset._rules import AssetRules
|
|
32
37
|
from cognite.neat.rules.models.dms._rules import DMSMetadata, DMSProperty, DMSRules
|
|
33
38
|
|
|
34
39
|
|
|
@@ -52,6 +57,28 @@ class _InformationRulesConverter:
|
|
|
52
57
|
def as_domain_rules(self) -> DomainRules:
|
|
53
58
|
raise NotImplementedError("DomainRules not implemented yet")
|
|
54
59
|
|
|
60
|
+
def as_asset_architect_rules(self) -> "AssetRules":
|
|
61
|
+
from cognite.neat.rules.models.asset._rules import AssetClass, AssetMetadata, AssetProperty, AssetRules
|
|
62
|
+
|
|
63
|
+
classes: SheetList[AssetClass] = SheetList[AssetClass](
|
|
64
|
+
data=[AssetClass(**class_.model_dump()) for class_ in self.rules.classes]
|
|
65
|
+
)
|
|
66
|
+
properties: SheetList[AssetProperty] = SheetList[AssetProperty]()
|
|
67
|
+
for prop_ in self.rules.properties:
|
|
68
|
+
if prop_.type_ == EntityTypes.data_property:
|
|
69
|
+
properties.append(
|
|
70
|
+
AssetProperty(**prop_.model_dump(), implementation=[AssetEntity(property=AssetFields.metadata)])
|
|
71
|
+
)
|
|
72
|
+
elif prop_.type_ == EntityTypes.object_property:
|
|
73
|
+
properties.append(AssetProperty(**prop_.model_dump(), implementation=[RelationshipEntity()]))
|
|
74
|
+
|
|
75
|
+
return AssetRules(
|
|
76
|
+
metadata=AssetMetadata(**self.rules.metadata.model_dump()),
|
|
77
|
+
properties=properties,
|
|
78
|
+
classes=classes,
|
|
79
|
+
prefixes=self.rules.prefixes,
|
|
80
|
+
)
|
|
81
|
+
|
|
55
82
|
def as_dms_architect_rules(self) -> "DMSRules":
|
|
56
83
|
from cognite.neat.rules.models.dms._rules import (
|
|
57
84
|
DMSContainer,
|
|
@@ -49,7 +49,7 @@ from cognite.neat.rules.models.entities import (
|
|
|
49
49
|
)
|
|
50
50
|
|
|
51
51
|
if TYPE_CHECKING:
|
|
52
|
-
from cognite.neat.rules.models
|
|
52
|
+
from cognite.neat.rules.models import AssetRules, DMSRules
|
|
53
53
|
|
|
54
54
|
|
|
55
55
|
if sys.version_info >= (3, 11):
|
|
@@ -341,6 +341,11 @@ class InformationRules(BaseRules):
|
|
|
341
341
|
|
|
342
342
|
return _InformationRulesConverter(self).as_domain_rules()
|
|
343
343
|
|
|
344
|
+
def as_asset_architect_rules(self) -> "AssetRules":
|
|
345
|
+
from ._converter import _InformationRulesConverter
|
|
346
|
+
|
|
347
|
+
return _InformationRulesConverter(self).as_asset_architect_rules()
|
|
348
|
+
|
|
344
349
|
def as_dms_architect_rules(self) -> "DMSRules":
|
|
345
350
|
from ._converter import _InformationRulesConverter
|
|
346
351
|
|
|
@@ -9,18 +9,10 @@ from cognite.client.data_classes._base import (
|
|
|
9
9
|
T_WriteClass,
|
|
10
10
|
WriteableCogniteResourceList,
|
|
11
11
|
)
|
|
12
|
-
from cognite.client.data_classes.data_modeling import (
|
|
13
|
-
DataModelingId,
|
|
14
|
-
)
|
|
15
|
-
from cognite.client.data_classes.data_modeling.ids import (
|
|
16
|
-
InstanceId,
|
|
17
|
-
VersionedDataModelingId,
|
|
18
|
-
)
|
|
19
12
|
from cognite.client.utils.useful_types import SequenceNotStr
|
|
20
13
|
|
|
21
|
-
from .
|
|
14
|
+
from cognite.neat._shared import T_ID
|
|
22
15
|
|
|
23
|
-
T_ID = TypeVar("T_ID", bound=str | int | DataModelingId | InstanceId | VersionedDataModelingId | RawTableID)
|
|
24
16
|
T_WritableCogniteResourceList = TypeVar("T_WritableCogniteResourceList", bound=WriteableCogniteResourceList)
|
|
25
17
|
|
|
26
18
|
|
|
@@ -41,7 +41,8 @@ from ._base import T_ID, ResourceLoader, T_WritableCogniteResourceList
|
|
|
41
41
|
class DataModelingLoader(
|
|
42
42
|
ResourceLoader[T_ID, T_WriteClass, T_WritableCogniteResource, T_CogniteResourceList, T_WritableCogniteResourceList]
|
|
43
43
|
):
|
|
44
|
-
|
|
44
|
+
@classmethod
|
|
45
|
+
def in_space(cls, item: T_WriteClass | T_WritableCogniteResource | T_ID, space: set[str]) -> bool:
|
|
45
46
|
if hasattr(item, "space"):
|
|
46
47
|
return item.space in space
|
|
47
48
|
raise ValueError(f"Item {item} does not have a space attribute")
|
cognite/neat/utils/upload.py
CHANGED
|
@@ -1,69 +1,89 @@
|
|
|
1
1
|
from abc import ABC
|
|
2
2
|
from dataclasses import dataclass, field
|
|
3
3
|
from functools import total_ordering
|
|
4
|
+
from typing import Any, Generic
|
|
4
5
|
|
|
6
|
+
from cognite.neat._shared import T_ID, NeatList, NeatObject
|
|
5
7
|
from cognite.neat.issues import NeatIssueList
|
|
6
8
|
|
|
7
9
|
|
|
8
10
|
@total_ordering
|
|
9
11
|
@dataclass
|
|
10
|
-
class UploadResultCore(ABC):
|
|
12
|
+
class UploadResultCore(NeatObject, ABC):
|
|
11
13
|
name: str
|
|
12
14
|
error_messages: list[str] = field(default_factory=list)
|
|
13
15
|
issues: NeatIssueList = field(default_factory=NeatIssueList)
|
|
14
16
|
|
|
15
17
|
def __lt__(self, other: object) -> bool:
|
|
16
|
-
if isinstance(other,
|
|
18
|
+
if isinstance(other, UploadResultCore):
|
|
17
19
|
return self.name < other.name
|
|
18
20
|
else:
|
|
19
21
|
return NotImplemented
|
|
20
22
|
|
|
21
23
|
def __eq__(self, other: object) -> bool:
|
|
22
|
-
if isinstance(other,
|
|
24
|
+
if isinstance(other, UploadResultCore):
|
|
23
25
|
return self.name == other.name
|
|
24
26
|
else:
|
|
25
27
|
return NotImplemented
|
|
26
28
|
|
|
29
|
+
def dump(self, aggregate: bool = True) -> dict[str, Any]:
|
|
30
|
+
return {"name": self.name}
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
class UploadResultList(NeatList[UploadResultCore]): ...
|
|
34
|
+
|
|
27
35
|
|
|
28
36
|
@dataclass
|
|
29
|
-
class
|
|
30
|
-
created:
|
|
31
|
-
deleted:
|
|
32
|
-
changed:
|
|
33
|
-
unchanged:
|
|
34
|
-
skipped:
|
|
35
|
-
failed_created:
|
|
36
|
-
failed_changed:
|
|
37
|
-
failed_deleted:
|
|
37
|
+
class UploadResult(UploadResultCore, Generic[T_ID]):
|
|
38
|
+
created: set[T_ID] = field(default_factory=set)
|
|
39
|
+
deleted: set[T_ID] = field(default_factory=set)
|
|
40
|
+
changed: set[T_ID] = field(default_factory=set)
|
|
41
|
+
unchanged: set[T_ID] = field(default_factory=set)
|
|
42
|
+
skipped: set[T_ID] = field(default_factory=set)
|
|
43
|
+
failed_created: set[T_ID] = field(default_factory=set)
|
|
44
|
+
failed_changed: set[T_ID] = field(default_factory=set)
|
|
45
|
+
failed_deleted: set[T_ID] = field(default_factory=set)
|
|
38
46
|
|
|
39
47
|
@property
|
|
40
|
-
def
|
|
41
|
-
return self.
|
|
48
|
+
def failed(self) -> int:
|
|
49
|
+
return len(self.failed_created) + len(self.failed_changed) + len(self.failed_deleted)
|
|
42
50
|
|
|
43
51
|
@property
|
|
44
|
-
def
|
|
45
|
-
return self.
|
|
52
|
+
def total(self) -> int:
|
|
53
|
+
return len(self.created) + len(self.deleted) + len(self.changed) + len(self.unchanged) + len(self.skipped)
|
|
46
54
|
|
|
47
|
-
def
|
|
48
|
-
|
|
55
|
+
def dump(self, aggregate: bool = True) -> dict[str, Any]:
|
|
56
|
+
output = super().dump(aggregate)
|
|
49
57
|
if self.created:
|
|
50
|
-
|
|
58
|
+
output["created"] = len(self.created) if aggregate else list(self.created)
|
|
59
|
+
if self.deleted:
|
|
60
|
+
output["deleted"] = len(self.deleted) if aggregate else list(self.deleted)
|
|
51
61
|
if self.changed:
|
|
52
|
-
|
|
53
|
-
if self.skipped:
|
|
54
|
-
line.append(f"skipped {self.skipped}")
|
|
62
|
+
output["changed"] = len(self.changed) if aggregate else list(self.changed)
|
|
55
63
|
if self.unchanged:
|
|
56
|
-
|
|
57
|
-
if self.
|
|
58
|
-
|
|
64
|
+
output["unchanged"] = len(self.unchanged) if aggregate else list(self.unchanged)
|
|
65
|
+
if self.skipped:
|
|
66
|
+
output["skipped"] = len(self.skipped) if aggregate else list(self.skipped)
|
|
59
67
|
if self.failed_created:
|
|
60
|
-
|
|
68
|
+
output["failed_created"] = len(self.failed_created) if aggregate else list(self.failed_created)
|
|
61
69
|
if self.failed_changed:
|
|
62
|
-
|
|
70
|
+
output["failed_changed"] = len(self.failed_changed) if aggregate else list(self.failed_changed)
|
|
63
71
|
if self.failed_deleted:
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
72
|
+
output["failed_deleted"] = len(self.failed_deleted) if aggregate else list(self.failed_deleted)
|
|
73
|
+
if self.error_messages:
|
|
74
|
+
output["error_messages"] = len(self.error_messages) if aggregate else self.error_messages
|
|
75
|
+
if self.issues:
|
|
76
|
+
output["issues"] = len(self.issues) if aggregate else [issue.dump() for issue in self.issues]
|
|
77
|
+
return output
|
|
78
|
+
|
|
79
|
+
def __str__(self) -> str:
|
|
80
|
+
dumped = self.dump(aggregate=True)
|
|
81
|
+
lines: list[str] = []
|
|
82
|
+
for key, value in dumped.items():
|
|
83
|
+
if key in ["name", "error_messages", "issues"]:
|
|
84
|
+
continue
|
|
85
|
+
lines.append(f"{key}: {value}")
|
|
86
|
+
return f"{self.name.title()}: {', '.join(lines)}"
|
|
67
87
|
|
|
68
88
|
|
|
69
89
|
@dataclass
|
|
@@ -71,6 +91,14 @@ class UploadResultIDs(UploadResultCore):
|
|
|
71
91
|
success: list[str] = field(default_factory=list)
|
|
72
92
|
failed: list[str] = field(default_factory=list)
|
|
73
93
|
|
|
94
|
+
def dump(self, aggregate: bool = True) -> dict[str, Any]:
|
|
95
|
+
output = super().dump(aggregate)
|
|
96
|
+
if self.success:
|
|
97
|
+
output["success"] = len(self.success) if aggregate else self.success
|
|
98
|
+
if self.failed:
|
|
99
|
+
output["failed"] = len(self.failed) if aggregate else self.failed
|
|
100
|
+
return output
|
|
101
|
+
|
|
74
102
|
|
|
75
103
|
@dataclass
|
|
76
104
|
class UploadDiffsID(UploadResultCore):
|
|
@@ -84,3 +112,15 @@ class UploadDiffsID(UploadResultCore):
|
|
|
84
112
|
result.success = self.created + self.changed + self.unchanged
|
|
85
113
|
result.failed = self.failed
|
|
86
114
|
return result
|
|
115
|
+
|
|
116
|
+
def dump(self, aggregate: bool = True) -> dict[str, Any]:
|
|
117
|
+
output = super().dump(aggregate)
|
|
118
|
+
if self.created:
|
|
119
|
+
output["created"] = len(self.created) if aggregate else self.created
|
|
120
|
+
if self.changed:
|
|
121
|
+
output["changed"] = len(self.changed) if aggregate else self.changed
|
|
122
|
+
if self.unchanged:
|
|
123
|
+
output["unchanged"] = len(self.unchanged) if aggregate else self.unchanged
|
|
124
|
+
if self.failed:
|
|
125
|
+
output["failed"] = len(self.failed) if aggregate else self.failed
|
|
126
|
+
return output
|
|
@@ -95,7 +95,7 @@ class DeleteDataModelFromCDF(Step):
|
|
|
95
95
|
report_lines = ["# Data Model Deletion from CDF\n\n"]
|
|
96
96
|
errors = []
|
|
97
97
|
for result in dms_exporter.delete_from_cdf(rules=input_rules, client=cdf_client, dry_run=dry_run):
|
|
98
|
-
report_lines.append(result
|
|
98
|
+
report_lines.append(str(result))
|
|
99
99
|
errors.extend(result.error_messages)
|
|
100
100
|
|
|
101
101
|
report_lines.append("\n\n# ERRORS\n\n")
|
|
@@ -216,8 +216,8 @@ class RulesToDMS(Step):
|
|
|
216
216
|
|
|
217
217
|
report_lines = ["# DMS Schema Export to CDF\n\n"]
|
|
218
218
|
errors = []
|
|
219
|
-
for result in dms_exporter.
|
|
220
|
-
report_lines.append(result
|
|
219
|
+
for result in dms_exporter.export_to_cdf_iterable(rules=input_rules, client=cdf_client, dry_run=dry_run):
|
|
220
|
+
report_lines.append(str(result))
|
|
221
221
|
errors.extend(result.error_messages)
|
|
222
222
|
|
|
223
223
|
report_lines.append("\n\n# ERRORS\n\n")
|
|
@@ -555,8 +555,8 @@ class RulesToCDFTransformations(Step):
|
|
|
555
555
|
|
|
556
556
|
report_lines = ["# DMS Schema Export to CDF\n\n"]
|
|
557
557
|
errors = []
|
|
558
|
-
for result in dms_exporter.
|
|
559
|
-
report_lines.append(result
|
|
558
|
+
for result in dms_exporter.export_to_cdf_iterable(rules=input_rules, client=cdf_client, dry_run=dry_run):
|
|
559
|
+
report_lines.append(str(result))
|
|
560
560
|
errors.extend(result.error_messages)
|
|
561
561
|
|
|
562
562
|
report_lines.append("\n\n# ERRORS\n\n")
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
cognite/neat/__init__.py,sha256=v-rRiDOgZ3sQSMQKq0vgUQZvpeOkoHFXissAx6Ktg84,61
|
|
2
|
-
cognite/neat/
|
|
2
|
+
cognite/neat/_shared.py,sha256=afQiTM0SvIKqeBRTvpfwwIvZL7QMQevt4F7lqRagAFg,968
|
|
3
|
+
cognite/neat/_version.py,sha256=V73U5VqNMlTo-QuWNLjECQI8_59YjD0cHrTa5BEP1lg,23
|
|
3
4
|
cognite/neat/app/api/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
4
5
|
cognite/neat/app/api/asgi/metrics.py,sha256=nxFy7L5cChTI0a-zkCiJ59Aq8yLuIJp5c9Dg0wRXtV0,152
|
|
5
6
|
cognite/neat/app/api/configuration.py,sha256=2U5M6M252swvQPQyooA1EBzFUZNtcTmuSaywfJDgckM,4232
|
|
@@ -70,14 +71,15 @@ cognite/neat/graph/issues/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJW
|
|
|
70
71
|
cognite/neat/graph/issues/loader.py,sha256=v8YDsehkUT1QUG61JM9BDV_lqowMUnDmGmbay0aFzN4,3085
|
|
71
72
|
cognite/neat/graph/loaders/__init__.py,sha256=hHC9sfFfbnGSVFTYeuNTIEu4tdLSJ2mWV07fereLelo,125
|
|
72
73
|
cognite/neat/graph/loaders/_base.py,sha256=bdYC6CwsHVqnQa1QzOhL68qQhF1OtrsearqH6D-z3E4,4037
|
|
73
|
-
cognite/neat/graph/loaders/
|
|
74
|
+
cognite/neat/graph/loaders/_rdf2asset.py,sha256=aFby7BwIrW253LEJ4XqGeUuf4jG9VUe8Lg7OlUnXMlM,4493
|
|
75
|
+
cognite/neat/graph/loaders/_rdf2dms.py,sha256=ZijbUsKOT01LBmTxsCgTw6lW65ysyxYe5aGOzD1l_r0,12991
|
|
74
76
|
cognite/neat/graph/models.py,sha256=AtLgZh2qyRP6NRetjQCy9qLMuTQB0CH52Zsev-qa2sk,149
|
|
75
77
|
cognite/neat/graph/queries/__init__.py,sha256=BgDd-037kvtWwAoGAy8eORVNMiZ5-E9sIV0txIpeaN4,50
|
|
76
78
|
cognite/neat/graph/queries/_base.py,sha256=20A7GDBdmc35VmHVz5n0YCGPcnBAmUX-bM2ImHPManc,3844
|
|
77
79
|
cognite/neat/graph/queries/_construct.py,sha256=FxzSQqzCpo7lKVYerlLAY03oqCeFM5L6MozfBUblzr4,7341
|
|
78
80
|
cognite/neat/graph/queries/_shared.py,sha256=EwW2RbPttt7-z7QTgfKWlthA2Nq5d3bYyyewFkCA7R4,5043
|
|
79
81
|
cognite/neat/graph/stores/__init__.py,sha256=G-VG_YwfRt1kuPao07PDJyZ3w_0-eguzLUM13n-Z_RA,64
|
|
80
|
-
cognite/neat/graph/stores/_base.py,sha256=
|
|
82
|
+
cognite/neat/graph/stores/_base.py,sha256=7NnJUh7SQ1lDfJruOgKWc2IesT1DC81Yi6Xqp44RFwM,10140
|
|
81
83
|
cognite/neat/graph/stores/_oxrdflib.py,sha256=A5zeRm5_e8ui_ihGpgstRDg_N7qcLZ3QZBRGrOXSGI0,9569
|
|
82
84
|
cognite/neat/graph/stores/_provenance.py,sha256=Hr9WBhFj-eoet4czL8XSBGYnu9Yn66YsTgH_G0n3QpY,3293
|
|
83
85
|
cognite/neat/graph/transformers/__init__.py,sha256=wXrNSyJNGnis3haaCKVPZ5y5kKSUsOUHnh-860ekatk,555
|
|
@@ -187,14 +189,14 @@ cognite/neat/rules/examples/__init__.py,sha256=nxIwueAcHgZhkYriGxnDLQmIyiT8PByPH
|
|
|
187
189
|
cognite/neat/rules/examples/wind-energy.owl,sha256=NuomCA9FuuLF0JlSuG3OKqD4VBcHgSjDKFLV17G1zV8,65934
|
|
188
190
|
cognite/neat/rules/exceptions.py,sha256=YLnsbXXJdDSr_szQoioEtOdqDV8PR7RdQjpMP2SWeCs,123868
|
|
189
191
|
cognite/neat/rules/exporters/__init__.py,sha256=Gn3CjkVKHJF9Po1ZPH4wAJ-sRW9up7b2CpXm-eReV3Q,413
|
|
190
|
-
cognite/neat/rules/exporters/_base.py,sha256=
|
|
191
|
-
cognite/neat/rules/exporters/_rules2dms.py,sha256=
|
|
192
|
+
cognite/neat/rules/exporters/_base.py,sha256=TkdpmliKjKVDITBAE4ySq_Zc8edFDQzHkbvHll4ODkg,1763
|
|
193
|
+
cognite/neat/rules/exporters/_rules2dms.py,sha256=xnmq4FbMAvYVtJzDM-wwTRwVq_t3XWf8ffmhpE27BSk,14547
|
|
192
194
|
cognite/neat/rules/exporters/_rules2excel.py,sha256=HvUdXYHxfLMijYWdTnfqCsw3Izf8S-XDSve-2ZbqF8Y,14248
|
|
193
195
|
cognite/neat/rules/exporters/_rules2ontology.py,sha256=Od53uLdcC2Q7UiF5PA2P0gw3O14eTD3MeJ1-trd64ZM,20388
|
|
194
196
|
cognite/neat/rules/exporters/_rules2yaml.py,sha256=GA8eUYRxUfIU6IMvlyGO5JidkOD5eUKSbH3qAiFiaCg,3026
|
|
195
197
|
cognite/neat/rules/exporters/_validation.py,sha256=OlKIyf4nhSDehJwFHDQ8Zdf6HpNfW7dSe2s67eywHu4,4078
|
|
196
198
|
cognite/neat/rules/importers/__init__.py,sha256=gR6_TAEa3iO5NCLKRztHg-FMiLdBnx47Z3iSzbwLfcE,481
|
|
197
|
-
cognite/neat/rules/importers/_base.py,sha256=
|
|
199
|
+
cognite/neat/rules/importers/_base.py,sha256=_hvxYnLiK8zf0MFes1VJ5TFisdZl-bOB6tFi3DQgYpc,4374
|
|
198
200
|
cognite/neat/rules/importers/_dms2rules.py,sha256=5yJGYkM7lAMu-QfO0_r59WE4RGtMu2smMqLm16ohgLQ,18994
|
|
199
201
|
cognite/neat/rules/importers/_dtdl2rules/__init__.py,sha256=CNR-sUihs2mnR1bPMKs3j3L4ds3vFTsrl6YycExZTfU,68
|
|
200
202
|
cognite/neat/rules/importers/_dtdl2rules/_unit_lookup.py,sha256=wW4saKva61Q_i17guY0dc4OseJDQfqHy_QZBtm0OD6g,12134
|
|
@@ -220,13 +222,13 @@ cognite/neat/rules/issues/spreadsheet_file.py,sha256=YCp0Pk_TsiqYuOPdWpjUpre-zvi
|
|
|
220
222
|
cognite/neat/rules/models/__init__.py,sha256=IqAg-h8PlcXcR_l-MECNMcVxMecF57vdg-Y488mBgWM,917
|
|
221
223
|
cognite/neat/rules/models/_base.py,sha256=uZrP_TRu3aljL3XZGMyNtlQDsMPwUEsfSNjGhRdMg88,11234
|
|
222
224
|
cognite/neat/rules/models/_constants.py,sha256=zPREgHT79_4FMg58QlaXc7A8XKRJrjP5SUgh63jDnTk,31
|
|
223
|
-
cognite/neat/rules/models/_rdfpath.py,sha256=
|
|
225
|
+
cognite/neat/rules/models/_rdfpath.py,sha256=t7h_9LMQrcj9JaYV2AXN_sYymbAvy-iyuAOjlhaTmog,12174
|
|
224
226
|
cognite/neat/rules/models/_types/__init__.py,sha256=l1tGxzE7ezNHIL72AoEvNHN2IFuitxOLxiHJG__s6t4,305
|
|
225
227
|
cognite/neat/rules/models/_types/_base.py,sha256=2GhLUE1ukV8X8SGL_JDxpbWGZyAvOnSqAE6JmDh5wbI,929
|
|
226
228
|
cognite/neat/rules/models/_types/_field.py,sha256=h2RrhjxdaRbzHG5EyduyHLkCJJmQoyZb9pYCkgMcnVk,3203
|
|
227
229
|
cognite/neat/rules/models/asset/__init__.py,sha256=qNon0kHleCPo2eT82TmeBAfiDDdwdKNU-Xdewuz8JRA,231
|
|
228
230
|
cognite/neat/rules/models/asset/_converter.py,sha256=PrTh9ZZkqSJBviiJE4xc3pClCsaWu2tTYOdgwg6_VOk,150
|
|
229
|
-
cognite/neat/rules/models/asset/_rules.py,sha256=
|
|
231
|
+
cognite/neat/rules/models/asset/_rules.py,sha256=fYp1pMJtioUtT747fo5NX69lgvPiPtHwXf_YuX--SEc,6195
|
|
230
232
|
cognite/neat/rules/models/asset/_rules_input.py,sha256=LiT-85CVgDz2ng65CtrRa77r4rnmg3E4Q6DC7-gv0dE,6257
|
|
231
233
|
cognite/neat/rules/models/asset/_serializer.py,sha256=ixqRf9qEzvChgysRaDX4g_vHVDtRBCsPYC9sOn0-ShE,3365
|
|
232
234
|
cognite/neat/rules/models/asset/_validation.py,sha256=86ymEgMZpG1eWu53PviUyUFnQBUJmYDZggUDXufBYLI,148
|
|
@@ -242,8 +244,8 @@ cognite/neat/rules/models/dms/_validation.py,sha256=5mk9L99FSwC8Ok7weEjnFJ_OZnmq
|
|
|
242
244
|
cognite/neat/rules/models/domain.py,sha256=wZ-DeIPFnacbNlxSrRuLzUpnhHdTpzNc22z0sDfisi4,2880
|
|
243
245
|
cognite/neat/rules/models/entities.py,sha256=qZa_PJOjFk3yTu5NyTSbAjsrU0HUxVnme_7YruBJoRQ,20460
|
|
244
246
|
cognite/neat/rules/models/information/__init__.py,sha256=HR6g8xgyU53U7Ck8pPdbT70817Q4NC1r1pCRq5SA8iw,291
|
|
245
|
-
cognite/neat/rules/models/information/_converter.py,sha256=
|
|
246
|
-
cognite/neat/rules/models/information/_rules.py,sha256=
|
|
247
|
+
cognite/neat/rules/models/information/_converter.py,sha256=nsfOCe13c3gqbbF1mrQHofemzYKpvg_NKjJZDwSXo5E,13960
|
|
248
|
+
cognite/neat/rules/models/information/_rules.py,sha256=TIFZhsPJhYkZjhAIu7iKegcp7Jgbd7iatDKMeC9x4gs,13403
|
|
247
249
|
cognite/neat/rules/models/information/_rules_input.py,sha256=ExCjcD0pvsThXYDf3uWYLzSLqN_2OtXFggbW_RB8hr4,10343
|
|
248
250
|
cognite/neat/rules/models/information/_serializer.py,sha256=yti9I_xJruxrib66YIBInhze___Io-oPTQH6uWDumPE,3503
|
|
249
251
|
cognite/neat/rules/models/information/_validation.py,sha256=Is2GzL2lZU3A5zPu3NjvlXfmIU2_Y10C5Nxi5Denz4g,7528
|
|
@@ -253,14 +255,14 @@ cognite/neat/utils/auxiliary.py,sha256=E2-YtddzScvN7l7j0kNYIMlfqIUT9NWMqLpcJYPK4
|
|
|
253
255
|
cognite/neat/utils/cdf.py,sha256=piRx-6GRz4cCfBZD5rU0OM6ixQ3cj5TMzI0yCYUveR8,2422
|
|
254
256
|
cognite/neat/utils/cdf_classes.py,sha256=NEmz5UprBlqfqZnqJkRk5xjSpzazwHbhcWsMH_GNxP8,5831
|
|
255
257
|
cognite/neat/utils/cdf_loaders/__init__.py,sha256=s2aPR5XLo6WZ0ybstAJlcGFYkA7CyHW1XO-NYpL0V6o,483
|
|
256
|
-
cognite/neat/utils/cdf_loaders/_base.py,sha256=
|
|
257
|
-
cognite/neat/utils/cdf_loaders/_data_modeling.py,sha256
|
|
258
|
+
cognite/neat/utils/cdf_loaders/_base.py,sha256=ryNC_AMXIESWXuTVJ-02L-HSVSpD6V49XdLTRYeFg70,1764
|
|
259
|
+
cognite/neat/utils/cdf_loaders/_data_modeling.py,sha256=-owgamlYnB4-hnvsvWiGPFcnvkKs0EzrrWmIKhnvBpI,11359
|
|
258
260
|
cognite/neat/utils/cdf_loaders/_ingestion.py,sha256=_2G8BObvpZ-vTHaCMAW_-ckHBLY96Hbg27uKAvpCaWk,6303
|
|
259
261
|
cognite/neat/utils/cdf_loaders/data_classes.py,sha256=0apspfwVlFltYOZfmk_PNknS3Z3SCxVr3kkvXH0bfPA,3844
|
|
260
262
|
cognite/neat/utils/exceptions.py,sha256=-w4cAcvcoWLf-_ZwAl7QV_NysfqtQzIOd1Ti-mpxJgM,981
|
|
261
263
|
cognite/neat/utils/spreadsheet.py,sha256=LI0c7dlW0zXHkHw0NvB-gg6Df6cDcE3FbiaHBYLXdzQ,2714
|
|
262
264
|
cognite/neat/utils/text.py,sha256=4bg1_Q0lg7KsoxaDOvXrVyeY78BJN8i-27BlyDzUCls,3082
|
|
263
|
-
cognite/neat/utils/upload.py,sha256=
|
|
265
|
+
cognite/neat/utils/upload.py,sha256=opAB8oDtpgcrugcjbUg0tjGqtFUnAS7zixtLiRYZ3TA,5084
|
|
264
266
|
cognite/neat/utils/utils.py,sha256=1LEwR8gpHw_6pvEeLkW_cDU_lUun4qSsw_Rr3JsKwgA,14172
|
|
265
267
|
cognite/neat/utils/xml.py,sha256=ppLT3lQKVp8wOP-m8-tFY8uB2P4R76l7R_-kUtsABng,992
|
|
266
268
|
cognite/neat/workflows/__init__.py,sha256=oiKub_U9f5cA0I1nKl5dFkR4BD8_6Be9eMzQ_50PwP0,396
|
|
@@ -289,7 +291,7 @@ cognite/neat/workflows/steps/lib/current/__init__.py,sha256=c22IznGdCSNCpXCi_yon
|
|
|
289
291
|
cognite/neat/workflows/steps/lib/current/graph_extractor.py,sha256=vW9UpJScx5dFVCSairpOdWRdBdLpkCt2kNh6litbF0o,5161
|
|
290
292
|
cognite/neat/workflows/steps/lib/current/graph_loader.py,sha256=HfGg1HRZhbV58TFu89FTjKeUxGsbCYLeFJIQFDN_pQM,2341
|
|
291
293
|
cognite/neat/workflows/steps/lib/current/graph_store.py,sha256=r7VTxdaz8jJQU7FJbnRDMxvEYbSAZFNMABhPyfNwiFk,6295
|
|
292
|
-
cognite/neat/workflows/steps/lib/current/rules_exporter.py,sha256=
|
|
294
|
+
cognite/neat/workflows/steps/lib/current/rules_exporter.py,sha256=1SKBYDnyDr975oMr9aOQVHExHjPQ0-whDDBNpTQ4K1A,23807
|
|
293
295
|
cognite/neat/workflows/steps/lib/current/rules_importer.py,sha256=23dxamGHSbJoG7qUqL4KiGznSmDTVHw1EfqhLCeAwDM,14695
|
|
294
296
|
cognite/neat/workflows/steps/lib/current/rules_validator.py,sha256=LwF9lXlnuPOxDSsOMMTHBi2BHc5rk08IF5zahS9yQuw,4844
|
|
295
297
|
cognite/neat/workflows/steps/lib/io/__init__.py,sha256=k7IPbIq3ey19oRc5sA_15F99-O6dxzqbm1LihGRRo5A,32
|
|
@@ -307,8 +309,8 @@ cognite/neat/workflows/steps_registry.py,sha256=fkTX14ZA7_gkUYfWIlx7A1XbCidvqR23
|
|
|
307
309
|
cognite/neat/workflows/tasks.py,sha256=dqlJwKAb0jlkl7abbY8RRz3m7MT4SK8-7cntMWkOYjw,788
|
|
308
310
|
cognite/neat/workflows/triggers.py,sha256=_BLNplzoz0iic367u1mhHMHiUrCwP-SLK6_CZzfODX0,7071
|
|
309
311
|
cognite/neat/workflows/utils.py,sha256=gKdy3RLG7ctRhbCRwaDIWpL9Mi98zm56-d4jfHDqP1E,453
|
|
310
|
-
cognite_neat-0.
|
|
311
|
-
cognite_neat-0.
|
|
312
|
-
cognite_neat-0.
|
|
313
|
-
cognite_neat-0.
|
|
314
|
-
cognite_neat-0.
|
|
312
|
+
cognite_neat-0.84.1.dist-info/LICENSE,sha256=W8VmvFia4WHa3Gqxq1Ygrq85McUNqIGDVgtdvzT-XqA,11351
|
|
313
|
+
cognite_neat-0.84.1.dist-info/METADATA,sha256=i54w9dUQS9DCWAsl2IR-P14CUA1uMLpjrdISbJXnL8o,9400
|
|
314
|
+
cognite_neat-0.84.1.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
|
|
315
|
+
cognite_neat-0.84.1.dist-info/entry_points.txt,sha256=61FPqiWb25vbqB0KI7znG8nsg_ibLHBvTjYnkPvNFso,50
|
|
316
|
+
cognite_neat-0.84.1.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|