Group by nested fields


#1

Hi,
I have problem on grouping by nested fields.

Let’s say, we have a list of companies who are moving packages from one location to another.
Data is defined like that:

mutation {
  schema {
    name: string @index(hash) .
    geoPoint: geo .
  }

  set {
    _:company1 <name> "Company A" .
    _:company1 <pickupFrom> _:company1_pickup_from .
    _:company1 <deliverTo> _:company1_deliver_to .
    _:company1_pickup_from <geoPoint> "{'type':'Point','coordinates':[0.0,0.0]}" .
    _:company1_deliver_to <geoPoint> "{'type':'Point','coordinates':[10.0,11.0]}" .

    _:company2 <name> "Company A" .
    _:company2 <pickupFrom> _:company2_pickup_from .
    _:company2 <deliverTo> _:company2_deliver_to .
    _:company2_pickup_from <geoPoint> "{'type':'Point','coordinates':[0.0,0.0]}" .
    _:company2_deliver_to <geoPoint> "{'type':'Point','coordinates':[10.0,11.0]}" .

    _:company3 <name> "Company A" .
    _:company3 <pickupFrom> _:company3_pickup_from .
    _:company3 <deliverTo> _:company3_deliver_to .
    _:company3_pickup_from <geoPoint> "{'type':'Point','coordinates':[0.0,0.0]}" .
    _:company3_deliver_to <geoPoint> "{'type':'Point','coordinates':[13.0,14.0]}" .
  }
}

Now I want to group by pickupFrom.geoPoint and deliverTo.geoPoint and count how many times packages were delivered from one point to another.
The result should be something like that:

[
    {
        pickupFrom: {'type':'Point','coordinates':[0.0,0.0]},
        deliverTo: {'type':'Point','coordinates':[10.0,11.0]},
        count: 2
    },
    {
        pickupFrom: {'type':'Point','coordinates':[0.0,0.0]},
        deliverTo: {'type':'Point','coordinates':[13.0,14.0]},
        count: 1
    }
]

It is working, when geo-points are on the same level:

mutation {
  schema {
    name: string @index(hash) .
    pickupFrom: geo .
    deliverTo: geo .
  }

  set {
    _:company1 <name> "Company B" .
    _:company1 <pickupFrom> "{'type':'Point','coordinates':[0.0,0.0]}" .
    _:company1 <deliverTo> "{'type':'Point','coordinates':[10.0,11.0]}" .

    _:company2 <name> "Company B" .
    _:company2 <pickupFrom> "{'type':'Point','coordinates':[0.0,0.0]}" .
    _:company2 <deliverTo> "{'type':'Point','coordinates':[10.0,11.0]}" .

    _:company3 <name> "Company B" .
    _:company3 <pickupFrom> "{'type':'Point','coordinates':[0.0,0.0]}" .
    _:company3 <deliverTo> "{'type':'Point','coordinates':[13.0,14.0]}" .
  }
}

{
  q(func: eq(name, "Company B")) @groupby(pickupFrom, deliverTo) {
    count(_uid_)
  }
}

Now, how could I group by nested fields that would result similar result set from first data set?


(Pawan Rawal) #2

Hey @rait.raidma

We don’t support @groupby using nested fields as of now. You can open an issue on Github and we can look into supporting this.


#3

Thank you for your answer.
I will open an issue.


(system) #4

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.