Query all Vertices and Edges in Graph that match a Filter

Hi all,

Brand new to TigerGraph, evaluating for a prototype, and I have a question I can’t easily find an answer to in the docs.

I have a bunch of vertices (called ‘system’) with an attribute ‘organisationId’, which is something of a top-level filter for systems.

Each system has 1 or more edges (‘circuit’) to other systems.

I will be updating the set of systems and their edges continuously via the REST API as the graph mutates.

My question is this; is there a way I can efficiently query tigergraph for the set of all vertices that match a particular filter and all the circuit edges between the matched vertices, without doing follow-up queries to get the edges one vertex at a time?

I can currently only see a way to get the matched vertices (with the filter parameter), and then separate individual calls to get the edges, specifying the source of the edge.

Thanks for any assistance,

Alistair

Hi Alistair,

You can use the query below as an outline to select your filtered vertices and only the edges connecting to them.

SetAccum<Edge> @@circuits

results = SELECT s FROM System:s - (circuit:e) - System:s2
WHERE
    s.organisationId == filtervalue
ACCUM
    @@circuits += e;

PRINT @@circuits;

The ACCUM statement will allow you to collect all the edges connected to the systems matching your filter criteria and store them in an accumulator for later use. If you wanted to maintain duplicate edges, then you can change the accumulator from a SetAccum to a BagAccum.

Super, thanks Dan.

For future people, I can neatly have multiple accumulators, and return both:

CREATE QUERY GetOrgEdges(STRING orgId) FOR GRAPH Network { 
  SetAccum<Edge> @@circuits;
  SetAccum<Vertex> @@vertices;

  res = SELECT s FROM System:s - (Circuit:e) - System:s2
  WHERE
      s.OrganisationId == orgId
  ACCUM
      @@vertices += s,
      @@circuits += e;

  PRINT @@vertices;
  PRINT @@circuits;
}

This lets me invoke the query with http://localhost:9000/query/Network/GetOrgEdges?orgId=ORG111, and I get both sets of data in one result set:

{
    "version": {
        "edition": "enterprise",
        "api": "v2",
        "schema": 2
    },
    "error": false,
    "message": "",
    "results": [
        {
            "@@vertices": [
                "JKL",
                "ABC",
                "DEF"
            ]
        },
        {
            "@@circuits": [
                {
                    "e_type": "Circuit",
                    "from_id": "JKL",
                    "from_type": "System",
                    "to_id": "ABC",
                    "to_type": "System",
                    "directed": false,
                    "attributes": {
                        "IsAnnounced": false
                    }
                },
                {
                    "e_type": "Circuit",
                    "from_id": "ABC",
                    "from_type": "System",
                    "to_id": "DEF",
                    "to_type": "System",
                    "directed": false,
                    "attributes": {
                        "IsAnnounced": false
                    }
                },
                {
                    "e_type": "Circuit",
                    "from_id": "ABC",
                    "from_type": "System",
                    "to_id": "JKL",
                    "to_type": "System",
                    "directed": false,
                    "attributes": {
                        "IsAnnounced": false
                    }
                },
                {
                    "e_type": "Circuit",
                    "from_id": "DEF",
                    "from_type": "System",
                    "to_id": "ABC",
                    "to_type": "System",
                    "directed": false,
                    "attributes": {
                        "IsAnnounced": false
                    }
                }
            ]
        }
    ]
}
1 Like