Skip to main content

Hi,

I have defined a Data model with two Views, say Employee and Address, both of this do not have any relationship.

For instances in Employee and Address view I have kept externalIds same, say emp101, emp102,... for both view instances.

Employee

extrenalId Name Age
emp101 Tom 30
emp102 Harry 28

 

Address

externalId City Pincode
emp101 Pune 123
emp102 Mumbai 456

 

I am using cognite sdk sync api call to synchronize instances of Employee view.

There is one Transformation on Address to update all the pincode values.

After running transformation, when sync api is called it always return all the values of Employee instances even if they are not updated. Is there any resolution to this unexpected behavior?

 

 

Hi @Akshay Hande 

Thanks for reaching out. Please see this article:

https://docs.cognite.com/cdf/dm/dm_concepts/dm_spaces_instances#external-ids

Do note that the unique identifier of an instance within a spaces is the externalId. So, if the transformation that updates pincodes is upserting emp101 this node is revised and will re-appear in the sync request.

So you should really use different external id for each instance, and rather model the relation between Employee and Address.

 

Hope this helps!

 

Arild


Hi @Arild Eide 

Thank you for your response, I understood your answer to my questions. But I have a solution model already defined and it contains plenty of existing data with the same externalIds similar to Employee and Address views example explained above. So is there any other way or a workaround which will allow me to get expected behavior without changing externalIds?

Sync api and its query I am using is like below

view_id = ViewId(space=<Employee_Space>, external_id=<Employee_View>, version=<Employee_View_Version>)
query = Query(
    with_ = {
        "nodes": NodeResultSetExpression(
            filter=HasData(views=tview_id]), 
            limit=2000)
    },
    select = {
        "nodes": Select()
    }
)
res = client.data_modeling.instances.sync(query)


Hi again, @Akshay Hande 

Please be aware that the sync api requires the client to preserve the cursor between each call, as shown in the example code in the SDK documentation.

For discriminating between Employees and Addresses, you cannot use the HasData filter, as both set of nodes will satisfy the filter. You might be able to use filter on a property of Address or Employee, like the prefix filter. Make sure to have an index for the property you are filtering by.

 

Arild

 


Hello @Arild Eide,

Thank you for your response. As per your comment for syc api cursor is being preserve for next call.

I also tried with prefix filter, but it is also giving me the all Employee instances, as the lastUpdatedTime is same in Both Employee and Address views after transformation run.

I have created zendesk ticket here: https://cognite.zendesk.com/hc/en-us/requests/12706 , to follow up further discussion


Reply