Aggregating facet variables


#1

I am trying to aggregate different facets on the same edge and I am not able to get the right query to do that. Is aggregation on facets on the same edge supported ?

For eg. my schema and data looks like this

    "client": [
      {
        "tenant": "tenant1",
        "connection": [
          {
            "connection|byteCount": 677628,
            "connection|dropPktCount": 0,
            "connection|pktCount": 5378,
            "connection|ts": "2019-07-06T07:20:59.535Z"
          },
          {
            "connection|byteCount": 601524,
            "connection|dropPktCount": 0,
            "connection|pktCount": 4774,
            "connection|ts": "2019-07-06T07:20:58.672Z"
          },
          {
            "connection|byteCount": 676872,
            "connection|dropPktCount": 0,
            "connection|pktCount": 5372,
            "connection|ts": "2019-07-06T07:30:59.56Z"
          },
          {
            "connection|byteCount": 677376,
            "connection|dropPktCount": 0,
            "connection|pktCount": 5376,
            "connection|ts": "2019-07-06T07:30:58.946Z"
          },
          {
            "connection|byteCount": 677250,
            "connection|dropPktCount": 0,
            "connection|pktCount": 5375,
            "connection|ts": "2019-07-06T07:20:59.535Z"
          },
          {
            "connection|byteCount": 678132,
            "connection|dropPktCount": 0,
            "connection|pktCount": 5382,
            "connection|ts": "2019-07-06T07:20:58.915Z"
          },
          {
            "connection|byteCount": 676620,
            "connection|dropPktCount": 0,
            "connection|pktCount": 5370,
            "connection|ts": "2019-07-06T07:30:58.663Z"
          },
          {
            "connection|byteCount": 677376,
            "connection|dropPktCount": 0,
            "connection|pktCount": 5376,
            "connection|ts": "2019-07-06T07:30:58.689Z"
          },
          {
            "connection|byteCount": 676998,
            "connection|dropPktCount": 0,
            "connection|pktCount": 5373,
            "connection|ts": "2019-07-06T07:20:58.672Z"
          },
          {
            "connection|byteCount": 677124,
            "connection|dropPktCount": 0,
            "connection|pktCount": 5374,
            "connection|ts": "2019-07-06T07:20:58.915Z"
          }
        ],
        "protocol": "TCP",
        "vrf": "ctx",
        "ip_port": "21.0.0.11_82",
        "epg": "bd1epg1",
        "ip": "21.0.0.11",
        "key": "21.0.0.11_82_ctx_TCP",
        "port": 82,

I am maintaining time series data as facets of each connection edge. Now if I want to sum up all connection|pktCount or connection|byteCount or aggregate the data based on time ranges using variable connection|ts. how do I achieve this ?

Thanks a ton !


(Michel Conrado) #2
{
  T as var(func: has(tenant), first:1) {
    connection @facets(a as pktCount) {
    total_pktCount as math(a)
}
      G as sum(val(total_pktCount))
  }

  q(func: uid(T)) {
    tenant
    val(G)
  }
}

And

you can use gt AND le

{
  T as var(func: has(tenant), first:1) {
    connection @facets(a as pktCount) @facets(gt(ts,"2019-07-06T07:20:58.672Z")) {
    total_pktCount as math(a)
}
      G as sum(val(total_pktCount))
  }

  q(func: uid(T)) {
    tenant
    val(G)
  }
}