Vertex-level Access Control Functions

These functions are only available for vertex aliases (defined in the FROM clause of a SELECT statement); they cannot be applied to vertex variables in other contexts.

Function

Description

Return type

v.isTaggable()

Return true if v is of a taggable vertex type.

BOOL

v.getTags()

Return v's set of tags. If v is untaggable, it returns an empty set.

SET<STRING>

v.hasTags(

STRING tag1,... STRING tagN)

Return true if v has every tag in the argument list of tags.

BOOL

v.intersectTags(

VERTEX v2)

Return the set of tags that v and v2 have in common.

SET<STRING>

v.differenceTags(

VERTEX v2)

Return the set of tags that v has but v2 does not have.

SET<STRING>

v.addTags(

STRING tag1,... STRING tagN)

Add the given tags to v.

n/a

v.removeTags(

STRING tag1,...

STRING tagN)

Remove the given tags from v.

n/a

v.removeAllTags()

Remove all tags from V.

n/a

Security Roles: In order to use these functions, a user must have admin or designer roles on the base graph. These funcitons cannot be used on a tag-based graph.

isTaggable()

This function returns true if the vertex is taggable.

Example:

//count the number of taggable vertices in the graph.
CREATE QUERY countIstaggable() for graph poc_graph_tag {
  SumAccum<int> @@count;
  vSet = { any };
  vSet = SELECT s
         FROM vSet:s
         WHERE s.isTaggable()
         ACCUM @@count += 1;
  PRINT @@count;
}

getTags()

This function returns the vertex's tags as a set. If the vertex has no tags or is untaggable, it returns an empty set.

Example:

//print the tags of each vertices, in 2 different ways.
CREATE QUERY exampleGettags() {
  SetAccum<string> @vAcc;
  vSet = { any };
  vSet = SELECT s
         FROM vSet:s
         ACCUM s.@vAcc += s.getTags();
  PRINT vSet[vSet.@vAcc];
  PRINT vSet[vSet.gettags()];
}

Tip: getTags() can be used within a PRINT statement:

  • PRINT R [R.getTags()];

  • or PRINT R WITH TAGS which is syntax sugar, except that it won’t print "R.getTags()": [] for non-taggable vertices.

hasTags(STRING tag1,... STRING tagN)

This function returns true if the vertex has every tag provided in the argument list and returns false if it does not.

Example:

USE GRAPH socialNet

CREATE QUERY findVertexWithTag(STRING tag) {
  seed = { ANY };
  res =
    SELECT v
    FROM seed:v
    WHERE v.hasTags(tag)
    ORDER BY v.id;
  PRINT res WITH TAGS;
}

INSTALL QUERY findVertexWithTag

RUN QUERY findVertexWithTag("vip")

The output of the query would be:

{
  "error": false,
  "message": "",
  "version": {
    "schema": 2,
    "edition": "enterprise",
    "api": "v2"
  },
  "results": [{"res": [
    {
      "v_id": "person6",
      "attributes": {
        "gender": "Male",
        "id": "person6",
        "res.gettags()": [
          "vip",
          "public"
        ]
      },
      "v_type": "person"
    },
    {
      "v_id": "person7",
      "attributes": {
        "gender": "Male",
        "id": "person7",
        "res.gettags()": [
          "vip",
          "public"
        ]
      },
      "v_type": "person"
    },
    {
      "v_id": "person8",
      "attributes": {
        "gender": "Male",
        "id": "person8",
        "res.gettags()": ["vip"]
      },
      "v_type": "person"
    }
  ]}]
}

intersectTags(VERTEX v2)

This function returns the common tags between the vertex and another vertex as a set.

Example:

//return the intersect set of tags between two vertices.
CREATE QUERY exampleIntersecttags() {
  SetAccum<string> @vAcc;
  vSet = { any };
  vSet = SELECT s
         FROM vSet:s -(_)-> :t
         WHERE t.type == "person"
         ACCUM s.@vAcc += s.intersectTags(t);
  PRINT vSet[vSet.@vAcc];
}

differenceTags(VERTEX v2)

This function returns the difference in tags between the vertex and another vertex as a set.

Example:

//return the difference set of tags between two vertices
CREATE QUERY exampleDifferencetags() {
  SetAccum<string> @vAcc;
  vSet = { any };
  vSet = SELECT s
         FROM vSet:s -(_)-> :t
         WHERE t.type == "person"
         ACCUM s.@vAcc += s.differenceTags(t);
  PRINT vSet[vSet.@vAcc];
}

addTags(STRING tag1,... STRING tagN)

This function adds the tags provided in the argument list to the vertex.

Example:

CREATE QUERY addTagsToPerson() {
  Seed = { any };
  # person1 ~ person5 will be tagged as public.
  vSet = SELECT s
         FROM Seed:s
         WHERE s.id IN ("person1","person2","person3","person4","person5")
         ACCUM s.addTags("public");

  # person6 and person7 will be tagged as public and vip.
  vSet = SELECT s
         FROM Seed:s
         WHERE s.id IN ("person6","person7")
         ACCUM s.addTags("vip", "public");

  # person8 will be tagged as vip
  vSet = SELECT s
         FROM Seed:s
         WHERE s.id == "person8"
         ACCUM s.addTags("vip");
}

removeTags(STRING tag1,... STRING tagN)

This function removes the tags provided in the argument list from the vertex.

//remove tag “vip” and “public” from all person vertices.
CREATE QUERY removetagsFromPerson() {
  vSet = { person.* };
  # remove tag vip and public from all person vertices
  vSet = SELECT s
         FROM vSet:s
         ACCUM s.removeTags("vip", "public");
}

removeAllTags()

This function removes all tags from the vertex.

Example:

//remove all tags from all person vertices.
CREATE QUERY removealltagsFromPerson() {
  vSet = { person.* };
  # remove all tags from all person vertices
  vSet = SELECT s
         FROM vSet:s
         ACCUM s.removeAllTags();
}

Last updated