This function is appended to neighbors(), neighborAttribute(), or edgeAttribute() to filter the output set according to a filter condition. Only elements that satisfy the condition will be returned.
Return type
BagAccum
Parameters
Example
Example query
CREATEQUERYfilterEx (SET<STRING> pIds,INTyr) FOR GRAPH workNet api("v2") {SetAccum<vertex<company>>@recentEmplr,@allEmplr;BagAccum<string>@diffCountry,@allCountry;Start={person.*};L0=SELECTvFROMStart:vWHEREv.idINpIdsACCUM# filter using edge attributev.@recentEmplr+=v.neighbors("worksFor").filter(worksFor.startYear>=yr),v.@allEmplr+=v.neighbors("worksFor").filter(true),# vertex alias attribute and neighbor type attributev.@diffCountry+=v.neighborAttribute("worksFor","company","id").filter(v.locationId!=company.country),v.@allCountry+=v.neighborAttribute("worksFor","company","id") ;PRINTyr,L0[L0.@recentEmplr,L0.@allEmplr,L0.@diffCountry,L0.@allCountry]; //apiv2}
From a vertex, traverses edges of a specified type to its neighbors of a specified type, and returns the set of values for a specified attribute.
Return type
BagAccum<attrType>
Parameters
Example
For the following graph:
# If v is Jennyv.neighborAttribute("friendship","person","state") -> ["ca", "ny", "ca"]
neighbors()
Syntax
v.neighbors([edgeType])
Description
Returns the out-neighbors or undirected neighbors of the vertex. If an edge type is provided, it will only return the neighbors connected by the specified edge type.
Return type
BagAccum<VERTEX>
Parameters
Example
For the following graph:
# If v is Jennyv.neighbors() -> ["Dan", "Amily", "Tom"]
outdegree()
Syntax
v.outdegree([edgeType])
Description
Returns the number of outgoing or undirected edges connected to the vertex. If an edge type is provided, it will only return the number of edges of the specified type.
Return type
Parameters
Note on outdegree(): This function reads a metadata value stored with each vertex, to avoid traversing the graph and thus have a fast response. The snapshot transaction semantics means that outdegree() may sometimes read an old value if there are concurrent write transactions. To guarantee an accurate count, traverse the neighboring edges and count them with a SumAccum, or use a function like neighbors() and then use size() on the set.
setAttr()
Syntax
v.setAttr( attrName, attrType, newValue )
Description
Sets the specified attribute of a vertex to a new value.
Return type
No return value.
Parameters
VLAC vertex alias methods
This section covers the vertex alias methods used to access and modify tags on vertices,
addTags()
Syntax
v.addTags(STRING tag1,... STRING tagN)
Description
Adds the tags provided in the argument list to the vertex.
Return type
No return value.
Parameters
Example:
CREATE QUERY addTagsToPerson() { Seed = { any };# person1 ~ person5 will be tagged as public. vSet =SELECT sFROM Seed:sWHERE s.id IN ("person1","person2","person3","person4","person5") ACCUM s.addTags("public");# person6 and person7 will be tagged as public and vip. vSet =SELECT sFROM Seed:sWHERE s.id IN ("person6","person7") ACCUM s.addTags("vip", "public");# person8 will be tagged as vip vSet =SELECT sFROM Seed:sWHERE s.id =="person8" ACCUM s.addTags("vip");}
differenceTags()
Syntax
v.differenceTags( v2 )
Description
Returns the difference in tags between the vertex and another vertex as a set.
Return type
SET<STRING>
Paramters
Example:
//return the difference set of tags between two verticesCREATE QUERY exampleDifferencetags() { SetAccum<string> @vAcc; vSet = { any }; vSet =SELECT sFROM vSet:s -(_)-> :tWHERE t.type =="person" ACCUM s.@vAcc += s.differenceTags(t);PRINT vSet[vSet.@vAcc];}
getTags()
Syntax
v.getTags()
Descriptions
Returns the vertex's tags as a set. If the vertex has no tags or is untaggable, it returns an empty set.
Return type
SET<STRING>
Parameters
None.
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()
Syntax
hasTags( tag1, tag2, ..., tagN )
Description
Returns true if the vertex has every tag provided in the argument list and returns false if it does not.
Return type
BOOL
Parameters
Example:
USE GRAPH socialNetCREATE 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 findVertexWithTagRUN QUERY findVertexWithTag("vip")
//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;}
intersectTags()
Syntax
v.intersectTags( v2 )
Description
Returns the common tags between the vertex and another vertex as a set.
Return type
SET<STRING>
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];}
removeAllTags()
Syntax
v.removeAllTags()
Description
Removes all tags from the vertex.
Return type
No return value.
Parameters
None
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();}
removeTags()
Syntax
removeTags( tag1, tag2, ..., tagN )
Description
Removes the tags provided in the argument list from the vertex.
Return type
No return value.
Parameters
Example
//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");}
Vertex functions
The functions in this section either have return values of vertex or vertex set type or are closely related to vertex attributes.
getvid()
Syntax
getvid( id )
Description
Returns the internal ID number of a vertex.
The internal ID is not the primary ID which the user assigned when creating the vertex. However, there is a 1-to-1 mapping between the external ID (primary_id) and internal ID.
The engine can access the internal ID faster than accessing the external ID, so if a query needs unique values for a large number of vertices, but doesn't care about particular values, getvid() can be a useful option. For example, in many community detection algorithms, we start by assigning every vertex a unique community ID. Then, as the algorithm progresses, some vertices will join the community of one of their neighbors, giving up their current community ID and copying the IDs of their neighbors.
Reads a data file that lists particular vertices of the graph and returns the corresponding vertex set. This function can only be used in a vertex set variable declaration statement as a seed set and the vertices in the data file must already be in the graph. The data file must be organized as a table with one or more columns. One column must be for vertex ID. Optionally, another column is for vertex type.
Return type
SET<VERTEX>
Parameters
Example
selectVertex.csv
ID,typeDan,personJenny,personAmily,person
Example query
CREATE QUERY selectVertexEx(STRING filename) FOR GRAPH socialNet { S1 = {SelectVertex(filename, $"c1", $1, ",", true)}; S2 = {SelectVertex(filename, $0, person, ",", true)};PRINT S1, S2; # Bothsets of inputs product the same result }