Bringing together the Apache Cassandra experts from the community and DataStax.

Want to learn? Have a question? Want to share your expertise? You are in the right place!

Not sure where to begin? Getting Started

 

question

sungop_187062 avatar image
sungop_187062 asked Erick Ramirez answered

Is it possible to do a GROUP BY on multiple columns and pick max value with DSE Graph?

I have following set of data in a vertex of graph DB.

userID(PK) product(CK) usage(CK) validFrom(CK) validTo(CK) lastUpdated (CK) location qty uom
1 aa 1 10/10/21 10/10/22 11/02/21 SJC 1 LB
1 aa 1 10/10/21 10/10/22 10/02/21 HH 2 LB
1 bb 1 10/10/21 10/10/22 11/02/21 ABC 1 LB
1 bb 1 10/10/21 10/10/22 10/02/21 BCD 40 LB

I will have to get the latest records based on the last updated date. The result should be below records.

1 aa 1 10/10/21 10/10/22 11/02/21 SJC 1 LB
1 bb 1 10/10/21 10/10/22 11/02/21 ABC 1 LB

Is it possible to get it through a gremlin query? I did try with the group by, but could not add more than one column. I need to have all the clustering keys in a group by except the last one. I will have to pick the latest last updated for each user,product, usage,validFrom and validTo group.

Do you recommend defining the graph schema in a different way? All I need the latest record for the given set of keys.

graph
10 |1000 characters needed characters left characters exceeded

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

1 Answer

Erick Ramirez avatar image
Erick Ramirez answered

Please log a ticket with DataStax Support so one of our engineers can assist you. Cheers!

Share
10 |1000 characters needed characters left characters exceeded

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.