Skip to content

Commit

Permalink
Merge branch 'main' into introduce-dms-maxmin
Browse files Browse the repository at this point in the history
  • Loading branch information
doctrino authored Mar 4, 2025
2 parents be32bf5 + a3a4785 commit 7183a25
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 8 deletions.
19 changes: 12 additions & 7 deletions cognite/neat/_rules/models/dms/_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
from collections import Counter, defaultdict
from collections.abc import Mapping
from functools import lru_cache
from typing import ClassVar

from cognite.client import data_modeling as dm
from cognite.client.data_classes.data_modeling import ContainerList, ViewId, ViewList
Expand All @@ -16,7 +15,12 @@
from cognite.neat._client import NeatClient
from cognite.neat._client.data_classes.data_modeling import ViewApplyDict
from cognite.neat._client.data_classes.schema import DMSSchema
from cognite.neat._constants import COGNITE_MODELS, DMS_CONTAINER_PROPERTY_SIZE_LIMIT, DMS_VIEW_CONTAINER_SIZE_LIMIT
from cognite.neat._constants import (
COGNITE_MODELS,
COGNITE_SPACES,
DMS_CONTAINER_PROPERTY_SIZE_LIMIT,
DMS_VIEW_CONTAINER_SIZE_LIMIT,
)
from cognite.neat._issues import IssueList, NeatError
from cognite.neat._issues.errors import (
CDFMissingClientError,
Expand Down Expand Up @@ -54,10 +58,6 @@ class DMSValidation:
"""This class does all the validation of the DMS rules that have dependencies between
components."""

# When checking for changes extension=addition, we need to check if the new view has changed.
# For example, changing the filter is allowed, but changing the properties is not.
changeable_view_attributes: ClassVar[set[str]] = {"filter"}

def __init__(
self,
rules: DMSRules,
Expand Down Expand Up @@ -91,6 +91,11 @@ def imported_views_and_containers_ids(
imported_views.add(prop.view)
view_with_properties.add(prop.view)

for container in self._containers or []:
for required in container.constraint or []:
if required not in existing_containers:
imported_containers.add(required)

if include_views_with_no_properties:
extra_views = existing_views - view_with_properties
imported_views.update({view for view in extra_views})
Expand Down Expand Up @@ -455,7 +460,7 @@ def _validate_referenced_container_limits(
def _validate_raw_filter(self) -> IssueList:
issue_list = IssueList()
for view in self._views:
if view.filter_ and isinstance(view.filter_, RawFilter):
if view.filter_ and isinstance(view.filter_, RawFilter) and view.view.space not in COGNITE_SPACES:
issue_list.append(
NotNeatSupportedFilterWarning(view.view.as_id()),
)
Expand Down
7 changes: 7 additions & 0 deletions tests/tests_integration/test_session/test_read.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,3 +73,10 @@ def test_data_model_views_not_in_same_space(self, cognite_client: CogniteClient)
neat._state.rule_store.last_issues[0],
ViewsAndDataModelNotInSameSpaceWarning,
)

def test_read_core_no_warnings(self, cognite_client: CogniteClient) -> None:
neat = NeatSession(client=cognite_client)

issues = neat.read.examples.core_data_model()

assert len(issues) == 0
31 changes: 30 additions & 1 deletion tests/tests_unit/rules/test_models/test_dms_rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
DMSValidation,
)
from cognite.neat._rules.models.dms._exporter import _DMSExporter
from cognite.neat._rules.models.entities._single_value import UnknownEntity, ViewEntity
from cognite.neat._rules.models.entities._single_value import ContainerEntity, UnknownEntity, ViewEntity
from cognite.neat._rules.transformers import (
DMSToInformation,
InformationToDMS,
Expand Down Expand Up @@ -1782,3 +1782,32 @@ def test_edge_types_by_view_property_id(
actual = exporter._edge_types_by_view_property_id(properties_by_view_id, view_by_id)

assert actual == expected_edge_types_by_view_property_id


class TestDMSValidation:
@pytest.mark.parametrize(
"input_rules, expected_views, expected_containers",
[
pytest.param(
DMSInputRules(
DMSInputMetadata("my_space", "MyModel", "Me", "v1"),
properties=[
DMSInputProperty("MyView", "name", "text", container="MyContainer", container_property="name"),
],
views=[DMSInputView("MyView")],
containers=[DMSInputContainer("MyContainer", constraint="cdf_cdm:CogniteDescribable")],
),
set(),
{ContainerEntity(space="cdf_cdm", externalId="CogniteDescribable")},
id="Container requiring other container",
)
],
)
def test_imported_views_and_containers_ids(
self, input_rules: DMSInputRules, expected_views: set[ViewEntity], expected_containers: set[ContainerEntity]
) -> None:
validation = DMSValidation(input_rules.as_verified_rules())
actual_views, actual_containers = validation.imported_views_and_containers_ids()

assert actual_views == expected_views
assert actual_containers == expected_containers

0 comments on commit 7183a25

Please sign in to comment.