0

I use orientDb with thinkerpop 3 support and the data is like this:

One country has multiple states and this states has multiple cities (one exception for my example is that not every state has cities).

I would like to count the states and the cities for one specific state in one gremlin query.

 ArrayList list = new ArrayList();

 g.V().has("key", GERMANY_KEY)
.repeat(__.in())
.until(__.hasLabel("state"))
.as("states")
.repeat(__.in())
.until(__.hasLabel("city"))
.as("cities")
.select("states", "cities")
.fill(list);

This is what I've but after this, I don't know I can count them together.

A possible answer from this could be

Germany has 16 states and 1000 cities.

Is this possible or do I need to make two queries?

Thanks a lot.

Neeraj Sewani
  • 3,952
  • 6
  • 38
  • 55
Marcel
  • 377
  • 5
  • 16

1 Answers1

0

I found a solution:

g.V().has("key", GERMAN_KEY)

                .repeat(__.in()).emit() 

                .groupCount().by(__.label())

                .forEachRemaining(e -> logger.info("Data: {}", e));
Marcel
  • 377
  • 5
  • 16