Gremlin query to group and count by multiple values

48 Views Asked by At

Having a schema like this one

(Page {name})-[HAS]->(Link {date, clicked})

I would like to retrieve records grouped by Page.name and Link.date, ordered by Link.date (desc)

Also, for each of these entry I want in the same record to know:

  • the total number of Links having same Link.date
  • the total number of Links having clicked == true

Something like this:

  • page=Page1, date=2023-06-08, total=3, clicked=1
  • page=Page2, date=2023-06-08, total=5, clicked=0
  • page=Page1, date=2023-06-07, total=1, clicked=0

I've tried to use group and groupCount, succeeding in retrieving the records grouped by Page with the details of their Link.date and count:

g.V().hasLabel('Page').as('p').outE().inV().as('l').group().by(select('p').by('name')).by(select('l').by('date').groupCount()).unfold()

  • ==>Page2={Thu Jun 08 00:00:00 CEST 2023=5}
  • ==>Page1={Wed Jun 07 00:00:00 CEST 2023=1, Tue Jun 08 00:00:00 CEST 2023=3}

But I cannot understand how to aggregate again ('l') with a where clause and how to appropriately form the records in the way that i need.

0

There are 0 best solutions below