Skip to main content
Solved

How to populate Edge properties?

  • February 27, 2025
  • 1 reply
  • 29 views

Hi,

I understand that we can define properties on edges, but it isn’t clear from the documentation how these properties are populated. I am trying to implement the following model

And defined the data model using DML as follows
 

How can I add a UserActivity edge with properties start_time and stop_time, that I can read while listing all the activities that a User has performed?

Thank you

Best answer by Arild Eide

Hi ​@Yatish Pitta 

 

The model definition you have provided will create a view UserActvitivy and a corresponding container to hold the edge properties. To populate edges you can use the Python SDK like this:


 

from cognite.client import CogniteClient
import cognite.client.data_classes.data_modeling as dm

client = CogniteClient()


client.data_modeling.instances.apply(
        edges=dm.EdgeApply(
            space=space_name,
            external_id="user_activity001", # external id of the edge you are creating
            type=dm.DirectRelationReference(space=space_name, external_id="User.activity"),  # Required type property
            start_node=dm.DirectRelationReference(space=space_name, external_id="activity001"), # Assuming presence of this activity node
            end_node=dm.DirectRelationReference(space=space_name, external_id="user001"), // Assuming presence of this user nade
            sources=[
                dm.NodeOrEdgeData(
                    # View version for UserActivity is auto created

                    source=dm.ViewId(space=space_name, external_id="UserActivity", version=version),
                    properties={"start_time": "2025-02-28T09:00:00", "stop_time": "2025-02-28T09:01:00"},
                )
            ],
        )
)

Hope this helps.

 

Arild Eide

View original
Did this topic help you find an answer to your question?

1 reply

Forum|alt.badge.img
  • Seasoned Practitioner
  • 38 replies
  • Answer
  • February 28, 2025

Hi ​@Yatish Pitta 

 

The model definition you have provided will create a view UserActvitivy and a corresponding container to hold the edge properties. To populate edges you can use the Python SDK like this:


 

from cognite.client import CogniteClient
import cognite.client.data_classes.data_modeling as dm

client = CogniteClient()


client.data_modeling.instances.apply(
        edges=dm.EdgeApply(
            space=space_name,
            external_id="user_activity001", # external id of the edge you are creating
            type=dm.DirectRelationReference(space=space_name, external_id="User.activity"),  # Required type property
            start_node=dm.DirectRelationReference(space=space_name, external_id="activity001"), # Assuming presence of this activity node
            end_node=dm.DirectRelationReference(space=space_name, external_id="user001"), // Assuming presence of this user nade
            sources=[
                dm.NodeOrEdgeData(
                    # View version for UserActivity is auto created

                    source=dm.ViewId(space=space_name, external_id="UserActivity", version=version),
                    properties={"start_time": "2025-02-28T09:00:00", "stop_time": "2025-02-28T09:01:00"},
                )
            ],
        )
)

Hope this helps.

 

Arild Eide


Reply


Cookie Policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie Settings