Skip to main content
Gathering Interest

Enable aggregate query (Min, Max) on timestamp typed properties

Related products:API and SDKs
  • ibrahim.alsyed
  • Marissa
  • RodrigoRVSN

Currently, it's not possible to use the aggregate query options on both Graphql and SDK for timestamp typed properties. So, for example, if I have a data structure that contains user information and the timestamps of when the user has accessed an application, and I want to get the latest (max), I can't without actually retrieving all the logs and then getting the maximum.

3 replies

Everton Colling
Seasoned Practitioner
Forum|alt.badge.img

Hi @Marissa!


Thank you for suggesting this product idea. We will follow the traction this idea gets in the community. You can expect updates on this post if we decide to include this in our future roadmap, or if we require more information.


kelvin
Seasoned Practitioner
  • Seasoned Practitioner
  • 53 replies
  • October 24, 2024

Hey Marissa! You’re right that currently you cannot aggregate on timestamp properties in Data Modeling, however, for you specific use case, assuming the timestamp is a property defined by you (and not one of the automatically populated `createdTime` and `lastUpdatedTime`) you should be able to construct a query that

  1. Gets all instances
  2. Sort by timestamp, descending
  3. Limit to 1

In this way you should be able to get the latest date. Here’s an example from GraphQL, that will return only the latest timestamp:

query MostRecentActivity {
  listCogniteActivity(first: 1, sort: {startTime: DESC_NULLS_LAST}) {
    items {
      startTime
    }
  }
}

 


Forum|alt.badge.img+3
  • Author
  • Active
  • 1 reply
  • October 25, 2024

Hi @kelvin,

Unfortunately, this doesn’t work in my case because I need to get the latest activity grouped by another field. E.g.: a user has an access history for multiple sites, so I want to get the latest activity per website for this user.


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