No, we do not have a distinct filter. But I might be missing something here, but can’t this be solved with aggregation? Something like
from cognite.client.data_classes.aggregations import Count
view_id= ViewId(space="slb-pdm-dm-governed", external_id="TimeseriesProperty",version="2_0")
client.data_modeling.instances.aggregate(view_id, Count("propertyType"), limit=10)
Hi @Anders Albert !
Thank you for the response. This gives the count of "TimeseriesPropertyType" instances that are attached to "TimeseriesProperty" view, which has a lot of duplicates. we only what unique values of "TimeseriesPropertyType" instances that are attached to "TimeseriesProperty" view. is there any way to achieve that?
Thanks for the clarification. I think the the following should do the trick.
view_id= ViewId(space="slb-pdm-dm-governed", external_id="TimeseriesProperty",version="2_0")
v_id_2_PROP = ViewId(space="slb-pdm-dm-governed", external_id="TimeseriesPropertyType",version="2_0")
query= Query(
with_=
{
"TimeseriesProperty":NodeResultSetExpression(
limit=10,
filter= HasData(views=[view_id])),
"TimeseriesPropertyType":NodeResultSetExpression(
limit=10000,
direction="outwards",
from_ = "TimeseriesProperty",
through = view_id.as_property_ref("propertyType"),
filter= HasData(views=[v_id_2_PROP]))
}
,
select={
"TimeseriesPropertyType": Select([SourceSelector(view_id, properties=['*'])]),
})
result = client.data_modeling.instances.query(query)
Note the difference between this an the original query is the select part. You select ‘TimeseriesPropertyType’, which will return only the unique TimeSeriesPropertyTypes regardless if it is linked to multiple timeseries properties.
hi @Anders Albert !
This gives the unique TimeSeriesPropertyTypes with its externalId and space, but this doesn’t give all fields from ‘TimeSeriesPropertyTypes’ view, just its space and externalId. do i need to extend this query?
the ‘TimeSeriesPropertyType’ view also has additional direct reference to 9 other views. so if i want to fetch say external Id of these 9 fields, i would need to extend the query for all 9 views like i did for dimension?:
type TimeSeriesPropertyType
name: String!
description: String!
dimension: PropertyDimension
# like that 8 other view reference
}
query= Query(
with_=
{
"TimeseriesProperty":NodeResultSetExpression(
limit=10,
filter= HasData(views=Dview_id_ts])),
"TimeseriesPropertyType":NodeResultSetExpression(
limit=10000, #resolve cursor!
direction="outwards",
from_ = "TimeseriesProperty",
through = view_id_ts.as_property_ref("propertyType"),
filter= HasData(views=Dview_TS_PROP_TYPE])),
"dimension":NodeResultSetExpression(
limit=10000, #resolve cursor!
direction="outwards",
from_ = "TimeseriesPropertyType",
through = view_TS_PROP_TYPE.as_property_ref("dimension"),
filter= HasData(views=DViewId(space="slb-pdm-dm-governed", external_id="PropertyDimension",version="1_0")]))
}
,
select={
"TimeseriesPropertyType": Select(eSourceSelector(view_id_ts, properties= r "*" ])]),
"TimeseriesProperty": Select(ySourceSelector(view_id_ts, properties=p"*"])]),
"dimension": Select(nSourceSelector(ViewId(space="slb-pdm-dm-governed", external_id="PropertyDimension",version="1_0"), properties= r "*" ])]),
},
cursors= {"TimeseriesProperty": nextcursor}
)
able to get the details that i need if i change the view_id in select statement:
select={ "TimeseriesPropertyType": Select([SourceSelector(view_TS_PROP_TYPE, properties=['*'])]), })
going ahead and closing this.