cognite-neat 1.0.16__py3-none-any.whl → 1.0.17__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.
@@ -79,3 +79,10 @@ class Provenance(UserList[Change]):
79
79
  def provenance_without_failures(self) -> "Provenance":
80
80
  """This method removes all the failed changes from the provenance list."""
81
81
  raise NotImplementedError("Not implemented yet")
82
+
83
+ def last_physical_data_model_read(self) -> Change | None:
84
+ """Get last physical data model read change"""
85
+ for change in reversed(self):
86
+ if change.activity.startswith("to_data_model"):
87
+ return change
88
+ return None
@@ -11,7 +11,9 @@ from cognite.neat._data_model.deployer.data_classes import DeploymentResult
11
11
  from cognite.neat._data_model.deployer.deployer import SchemaDeployer
12
12
  from cognite.neat._data_model.exporters import DMSExporter, DMSFileExporter
13
13
  from cognite.neat._data_model.exporters._api_exporter import DMSAPIExporter
14
+ from cognite.neat._data_model.exporters._table_exporter.exporter import DMSTableExporter
14
15
  from cognite.neat._data_model.importers import DMSImporter, DMSTableImporter
16
+ from cognite.neat._data_model.importers._api_importer import DMSAPIImporter
15
17
  from cognite.neat._data_model.models.dms import RequestSchema as PhysicalDataModel
16
18
  from cognite.neat._data_model.models.dms._limits import SchemaLimits
17
19
  from cognite.neat._exceptions import DataModelImportException
@@ -62,7 +64,9 @@ class NeatStore:
62
64
  else:
63
65
  activity = writer.export
64
66
 
65
- change, _ = self._do_activity(activity, on_success, data_model=self.physical_data_model[-1], **kwargs)
67
+ data_model = self._gather_data_model(writer)
68
+
69
+ change, _ = self._do_activity(activity, on_success, data_model=data_model, **kwargs)
66
70
 
67
71
  if not change.issues:
68
72
  change.target_entity = "ExternalEntity"
@@ -79,6 +83,35 @@ class NeatStore:
79
83
  # Update CDF snapshot after successful deployment
80
84
  self.cdf_snapshot = SchemaSnapshot.fetch_entire_cdf(self._client)
81
85
 
86
+ def _gather_data_model(self, writer: DMSExporter) -> PhysicalDataModel:
87
+ """Gather the current physical data model from the store
88
+
89
+ Args:
90
+ writer (DMSExporter): The exporter that will be used to write the data model.
91
+ """
92
+ # getting provenance of the last successful physical data model read
93
+ change = self.provenance.last_physical_data_model_read()
94
+
95
+ if not change:
96
+ raise RuntimeError("No successful physical data model read found in provenance.")
97
+
98
+ # We do not want to modify the data model for API representations
99
+ if not (change.agent == DMSAPIImporter.__name__ and isinstance(writer, DMSTableExporter)):
100
+ return self.physical_data_model[-1]
101
+
102
+ # This will handle data model that are partially and require to be converted to
103
+ # tabular representation to include all containers referenced by views.
104
+ copy = self.physical_data_model[-1].model_copy(deep=True)
105
+ container_refs = {container.as_reference() for container in copy.containers}
106
+
107
+ for view in copy.views:
108
+ for container in view.used_containers:
109
+ if container not in container_refs and (cdf_container := self.cdf_snapshot.containers.get(container)):
110
+ copy.containers.append(cdf_container)
111
+ container_refs.add(container)
112
+
113
+ return copy
114
+
82
115
  def _can_agent_do_activity(self, agent: Agents) -> None:
83
116
  """Validate if activity can be performed in the current state and considering provenance"""
84
117
  if not self.state.can_transition(agent):
cognite/neat/_version.py CHANGED
@@ -1,2 +1,2 @@
1
- __version__ = "1.0.16"
1
+ __version__ = "1.0.17"
2
2
  __engine__ = "^2.0.4"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: cognite-neat
3
- Version: 1.0.16
3
+ Version: 1.0.17
4
4
  Summary: Knowledge graph transformation
5
5
  Author: Nikola Vasiljevic, Anders Albert
6
6
  Author-email: Nikola Vasiljevic <nikola.vasiljevic@cognite.com>, Anders Albert <anders.albert@cognite.com>
@@ -112,8 +112,8 @@ cognite/neat/_state_machine/__init__.py,sha256=wrtQUHETiLzYM0pFo7JC6pJCiXetHADQb
112
112
  cognite/neat/_state_machine/_base.py,sha256=-ZpeAhM6l6N6W70dET25tAzOxaaK5aa474eabwZVzjA,1112
113
113
  cognite/neat/_state_machine/_states.py,sha256=nmj4SmunpDYcBsNx8A284xnXGS43wuUuWpMMORha2DE,1170
114
114
  cognite/neat/_store/__init__.py,sha256=TvM9CcFbtOSrxydPAuJi6Bv_iiGard1Mxfx42ZFoTl0,55
115
- cognite/neat/_store/_provenance.py,sha256=tWQGa2QNPyW7FfHQBRto9eHXCxeOTzlz7DvYjAwHfuY,3102
116
- cognite/neat/_store/_store.py,sha256=79D3aczHRJiPIdivusxulaMig516hFagM7o5P5tCnDs,7773
115
+ cognite/neat/_store/_provenance.py,sha256=1zzRDWjR9twZu2jVyIG3UdYdIXtQKJ7uF8a0hV7LEuA,3368
116
+ cognite/neat/_store/_store.py,sha256=Jibx6kKAH8V6iUOegDOcSLTplGLxmuXCLfjbdff_wvI,9367
117
117
  cognite/neat/_utils/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
118
118
  cognite/neat/_utils/_reader.py,sha256=9dXrODNNqWU0Gx1zXjRTOiiByFuDZlpQkQEzx3HAxYQ,5390
119
119
  cognite/neat/_utils/auxiliary.py,sha256=Cx-LP8dfN782R3iUcm--q26zdzQ0k_RFnVbJ0bwVZMI,1345
@@ -316,9 +316,9 @@ cognite/neat/_v0/session/_template.py,sha256=BNcvrW5y7LWzRM1XFxZkfR1Nc7e8UgjBClH
316
316
  cognite/neat/_v0/session/_to.py,sha256=AnsRSDDdfFyYwSgi0Z-904X7WdLtPfLlR0x1xsu_jAo,19447
317
317
  cognite/neat/_v0/session/_wizard.py,sha256=baPJgXAAF3d1bn4nbIzon1gWfJOeS5T43UXRDJEnD3c,1490
318
318
  cognite/neat/_v0/session/exceptions.py,sha256=jv52D-SjxGfgqaHR8vnpzo0SOJETIuwbyffSWAxSDJw,3495
319
- cognite/neat/_version.py,sha256=NWe6vYJNJJT0Uxz7Lq74J6fpGVLlbxI8usM-joa7U2M,45
319
+ cognite/neat/_version.py,sha256=o7GgrsHFEMJXof4FVslWa-ZccQkVdswvAIXHizqt_1I,45
320
320
  cognite/neat/legacy.py,sha256=eI2ecxOV8ilGHyLZlN54ve_abtoK34oXognkFv3yvF0,219
321
321
  cognite/neat/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
322
- cognite_neat-1.0.16.dist-info/WHEEL,sha256=KSLUh82mDPEPk0Bx0ScXlWL64bc8KmzIPNcpQZFV-6E,79
323
- cognite_neat-1.0.16.dist-info/METADATA,sha256=c8Vvlzs386LWDcbannET6hwQeUN3jqro7eLUdRRvzoQ,6091
324
- cognite_neat-1.0.16.dist-info/RECORD,,
322
+ cognite_neat-1.0.17.dist-info/WHEEL,sha256=KSLUh82mDPEPk0Bx0ScXlWL64bc8KmzIPNcpQZFV-6E,79
323
+ cognite_neat-1.0.17.dist-info/METADATA,sha256=o2xcMmYzEhkFNrboqpljF7fhET9EL6vJvjnUXdd15YI,6091
324
+ cognite_neat-1.0.17.dist-info/RECORD,,